GeeCON Prague 2014*
The moose likes Servlets and the fly likes Servlet calling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet calling" Watch "Servlet calling" New topic
Author

Servlet calling

Manish Jaju
Greenhorn

Joined: Jul 21, 2004
Posts: 24
When a servlet is called from other servlet using include or forward method of RequestDispatcher, at that time, are doGet or doPost methods (of called servlet) called from calling servlet??? Will someone elaborate this point, I mean explain flow of programm for same above. I will be hightly obliged.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
No.

when we do forward(), it means we are passing control to a new web resource, in your case to a servlet. now the new resource, which we have passed the control, is supposed to commit the response.

when we do include(), it means we are passing the control to a new web resource for some processing but the control would be back to the same resource. now the new resource, which we have passed the control, is supposed to process the request or manipulate the response but not commit the response. response would be commited by the same resource that has passed the control to a new resource for some processing only.

and about the method calling. no servlet calls the method doPost() or doGet() of any other resource. container knows which method it should call. because the request object has the method, by which the request is made. we can get that using request.getMethod(). now as we pass the request and response in our forward() and include() method, thus we need not worry.

cheers.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet calling