aspose file tools*
The moose likes Servlets and the fly likes servlets: can we override service method ?if yes how and why?if no then why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets: can we override service method ?if yes how and why?if no then why?" Watch "servlets: can we override service method ?if yes how and why?if no then why?" New topic
Author

servlets: can we override service method ?if yes how and why?if no then why?

Sashidhar Rao Gopisetty
Greenhorn

Joined: Sep 23, 2005
Posts: 19
i hav few doubts in servlets
1)servlets can have user defined methods then how we can call them from other servlet
2)if servlets have session and context how we can we can call the userdefined methods
3)how we can override service method


�Don't limit your challenges - challenge your limits.�<br /> <br />Thanks & Regards<br />GDS Sashidhar Rao
Keith Pitty
Ranch Hand

Joined: Sep 22, 2005
Posts: 32
Sashidhar,

Servlets are designed to be invoked to handle an HttpServletRequest. The servlet engine responds to requests by invoking the service method, which delegates to either doGet or doPost depending on the type of HTTP request.

So when we create a servlet we extend the HttpServlet class and typically override the doGet and doPost methods. We may delegate from either of these methods to other methods in our servlet but our servlet would be invoked via the service method invoking either doGet or doPost.

Firstly, methods in a servlet other than those that are being overridden should be private.

Secondly, methods other than those being overridden should only be called within the servlet.

Thirdly, the service method is not designed to be overridden.

I hope this helps.
[ September 23, 2005: Message edited by: Keith Pitty ]
Sashidhar Rao Gopisetty
Greenhorn

Joined: Sep 23, 2005
Posts: 19
hi Keith Pitty

how we can call the userdifined methods of one servlet from another servlet
Keith Pitty
Ranch Hand

Joined: Sep 22, 2005
Posts: 32
What do you mean by a user-defined method?
Keith Pitty
Ranch Hand

Joined: Sep 22, 2005
Posts: 32
If you want to call one servlet from another the technique is:

This forwards a request, response pair from the first servlet to the second where "/SecondServlet" is the servlet mapping defined in the deployment descriptor (web.xml) to the second servlet.

Does this help?
Sashidhar Rao Gopisetty
Greenhorn

Joined: Sep 23, 2005
Posts: 19
other than post get service ,some public methods to be used in servlet
Keith Pitty
Ranch Hand

Joined: Sep 22, 2005
Posts: 32
Servlets are not designed to be invoked via public methods directly. The Servlet API is designed to provide a way for Java to handle HTTP requests. This is why the service method delegates to doGet or doPost.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets: can we override service method ?if yes how and why?if no then why?