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
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 ]
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.
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.
Don't get me started about those stupid light bulbs.