aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How container Handle request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How container Handle request" Watch "How container Handle request" New topic
Author

How container Handle request

Gaurav Gambhir
Ranch Hand

Joined: Mar 04, 2006
Posts: 254
As per in the Head First book
container handle the request using following sequence

�User click a link that has a URL to a servlet instead of static page.
�The container sees that the request is for servlet so the container creates two objects

HttpServletResponse
HttpServletRequest
�The container finds the correct servlet based on the URL in the request,create or allocate a thread for that request and passes the request and response objects to the servlet thread.
�The container calls the servlet�s service() method.Depending on the type of request,the service() method calls either doGet() or doPost() method.
�The doGet() method generates the dynamic page and stuff the page into the response object.Remember the container still has a reference to response object.
�The thread completes, the container convets the response object into an HTTP response,send it back to client then delete the request and response objects.

-------------------------------------------------------------
Now my question is , container call which service() method,Is the following sequence right

�User click a link that has URL to a servlet instead of static page.
�The container sees that the request is for servlet so the container creates two objects.
HttpServletRequest
HttpServletResponse


�The container find the correct servlet based on the URL in the request create or allocate a thread for that request and passes the request and response objects to the servlet thread.
�The container calls the service(ServletRequest,ServletResponse) method of HttpServlet.
�The service(ServletRequest,ServletResponse) method of HttpServlet calls the service(HttpServletRequest,HttpServletResponse) method of the same class,the service() method is overloaded in HttpServlet class.
�The service(HttpServletRequest,HttpServletResponse) method of HttpServlet analyzes the request and find out which HTTP method is being used.Depending on HTTP method,it call the corresponding doXXX() method of servlet,for example if request is for the GET method, it calls the doGet() method of servlet.
�The doGet() method generates the dynamic page and stuff the page into response object.Remember the container still has reference to response object.
�The thread completes, the container convets the response object into an HTTP response,send it back to client then delete the request and response objects.
Chandra Sagi
Ranch Hand

Joined: May 05, 2005
Posts: 162
All servlets extend HttpServlet and it has a method service() which takes two arguments HttpServletRequest and HttpServletResponse which are the two objects being created as you said.

Thanks
Chandu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How container Handle request