wood burning stoves*
The moose likes Servlets and the fly likes RequestDispatcher.forward to another servlet to handle form in doPost? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher.forward to another servlet to handle form in doPost?" Watch "RequestDispatcher.forward to another servlet to handle form in doPost?" New topic
Author

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

Ken Flor
Ranch Hand

Joined: Aug 01, 2006
Posts: 34
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

Joined: Jan 24, 2005
Posts: 489

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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher.forward to another servlet to handle form in doPost?