Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher forwarding

 
David Tan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless specifically mentioned, all requests will invoke the doGet method as defalut.
regards,
ravi.
 
Afroz Ahmed
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic