This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher.forward to another servlet to handle form in doPost?

 
Ken Flor
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a servlet named ServletA. I did a RequestDispatcher.forward to ServletB.

However in ServletB, I have to handle a Post action due to form handling. However, it will not trigger the doPost in ServletB. Instead it triggers the doPost in ServletA. I do not wish it to trigger doPost in ServletA.

I cannot do a redirect from ServletA to ServletB as I need to retain the context information.

Any ideas?

Thanks
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a reason why you cant call the doPost() from the doGet() in servletB?

If the post request is mapped to ServletA, it will be the doPost() in ServletA that will be executed. Infact you receive an error if you dont have a doPost() method in ServletA.

And finally context information is available across requests (and sessions for that matter).

ram.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the request made to servlet A is of type POST and you forward to ServletB from within ServletA's doPost method the doPost method of ServletB will be called.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic