aspose file tools*
The moose likes Servlets and the fly likes service method in HttpServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "service method in HttpServlet" Watch "service method in HttpServlet" New topic
Author

service method in HttpServlet

thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
There are two service methods in HttpServlet abstrtact class (Service method is overloaded and overridden)
1.public method
2.protected method
Overrides:
service in class GenericServlet
public void service(ServletRequest req,ServletResponse res) throws ServletException,java.io.IOException
Dispatches client requests to the protected service method. There's no need to override this method.
Overloads :
protected void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,java.io.IOException
Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. This method is an HTTP-specific version of the Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) method.

Why deos it require two service methods in HttpServlet Class? As HttpServlet class is meant for HTTP protocol,then why does that specific class has another service mehod with parameters ServletRequest and ServletResponse ?
Understanding the sequence of events in HttpServlet
1.The servlet container calls the service(ServletRequest req,ServletResponse res) method f HttpServlet
2.The service(ServletRequest,ServletResponse) method of HttpServlet calls the service(HttopServletRequest ,HttpServletResponse ) method of the same class.
3.The service(HttopServletRequest ,HttpServletResponse ) method of HttpServlet analyzes the request and finds out which HTTP method is being used .

As per the above quote ,Container calls service method(ServletRequest,ServletResponse) and this method in turns calls service(HttopServletRequest ,HttpServletResponse ) method.How does the service method calls another service method in same class?In service method definition ,it is not calling another service method ..
Mahesh swami
Greenhorn

Joined: Aug 13, 2002
Posts: 26
See ,
HttpServlet class needs to override teh service() method in the GenericServlet class or else it would be a Abstract class.
Now it requires that the arguments to this method should be objects of type HttpServletRequest and HttpServletResponse. Hence it wraps the ServletRequest and ServletResponse type objects into required type and then calls the protected service()method. Which in turn checks for the Http method(Get/Post) and call doXXX method().
Eric Lidell
Greenhorn

Joined: Jul 02, 2003
Posts: 20
The service (ServletRequest request ,ServletResponse response) is used to override the genericservlet.and it transfers the code to service (HttpServletRequest,HttpServletResponse ) by probably inserting the following code.
service((HttpServletRequest) request,(HttpServletResponse)response)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: service method in HttpServlet
 
Similar Threads
service method...
Question Bank ID : 6
servlets
which service() method is called
service() method in GenericServlet & HttpServlet