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

RequestDispatcher forwarding

David Tan
Greenhorn

Joined: Sep 30, 2002
Posts: 9
When the servlet A forwards to another servlet B to generate response via RequestDispatcher.forward method, which method (doGet or doPost) of servlet B does the container invoke?
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
Unless specifically mentioned, all requests will invoke the doGet method as defalut.
regards,
ravi.
Afroz Ahmed
Ranch Hand

Joined: Jan 18, 2004
Posts: 64
Hello,
There are only 2 ways to send a post request..
1) specifying post as a mthod in a form tag
<form method="post" ...>
2) Clicking on anchor tag,which is calling a javascript method..and this javascript intern sends post request.
Except the above two cases,all the forwards are regarded as get request and calls doGet() method...
Thanks..
Regards
Afroz Ahmed.


The value of an idea lies in the usage of it.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
To be precise - the method GET or POST is set in a header that is part of the original request - the servlet that the request is being forwarded to will examine the request and use the appropriate method. You can change the method by means of a custom request wrapper if necessary.
Bill
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
To simplify what Bill said: if the original request was a GET request, a GET forward will be make; else if the original request was a POST request, a POST forward will be made.
To circumvent this behavior, the professional method is to do as Bill said and create a wrapper request.
The non-so professional method is to call either the doGet or doPost from each other and set some attributes as flags that will help you determine the proper course of action.
I have use the latter approach for an application where a wrapper would not do.


SCJP, SCWCD, SCBCD, IBM CSD WebSphere v5, <br />A+, MCP 2000 and 2000 server, CST, and few incompleted certification tracks.<br /> <br />Ivory Coast<br /> <br />Analyze your web Request/Response @ <a href="http://webtools.servehttp.com" target="_blank" rel="nofollow">http://webtools.servehttp.com</a> down for a while...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher forwarding