servlet execution
Hi! Please try to answer my question: if a servlet has 3 methods as service,doGet and doPost then which one gets executed first and does the request get passed to next method?
Hi! Please try to answer my question: if a servlet has 3 methods as service,doGet and doPost then which one gets executed first and does the request get passed to next method?
From the javadocs for HttpServlet:
public abstract class HttpServlet
extends GenericServlet
implements java.io.Serializable
Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these:
* doGet, if the servlet supports HTTP GET requests
* doPost, for HTTP POST requests
* doPut, for HTTP PUT requests
* doDelete, for HTTP DELETE requests
* init and destroy, to manage resources that are held for the life of the servlet
* getServletInfo, which the servlet uses to provide information about itself
There's almost no reason to override the service method. service handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doXXX methods listed above).
So service is called, and it dispatches to doGet, doPost, etc. based on the HTTP request type.
Yes, the request and response objects from service are passed along.
%
Thanks for ur response. It helped me.