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

forwarding a request a second time

Sven Anderson
Ranch Hand

Joined: Apr 14, 2004
Posts: 58
Hi all,
I'm working on a small servlet application and I've got the following problem with my code:
Ive got a dispatcher servlet that redirect all user requests to various servlets etc.
the problem I have with the following code is that I want to do a second forwarding to another servlet after I've done the first one. Alternatively I would like to call my dispatcher servlet again and pass a new parameter so that my first "else if" statement is triggered. I'm stucked with this problem and dont know how to continue.
else if(userRequest.equals("openForum"))
{
String redirectTo ="/servlet/ListTopicsMessages";
RequestDispatcher dispatcher = req.getRequestDispatcher(redirectTo);
dispatcher.forward(req, res);
}
else if(userRequest.equals("postTopic"))
{
String redirectTo ="/servlet/ForumOperations";
RequestDispatcher dispatcher = req.getRequestDispatcher(redirectTo);
dispatcher.forward(req, res);
// I want to do a second forwarding here to my ListTopicsMessages servlet
}

I would be very happy If someone would be able to help me with this
Regards
Erik
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
Use filters along with a response wrapper.
The problem you are having is that one of the fowarded to servlet commits the response. Using a HttpServletResponseWrapper in a filter will fix your design issue. Note that you can have multiple filters that will call each another in succession based on your filters mapping.


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...
Sven Anderson
Ranch Hand

Joined: Apr 14, 2004
Posts: 58
Thanks for you quick reply.
I'm actually reading about filters right now in the JWSDP tutorial section.
The reason I want to do a second forward is to after the "update" in the DB direct the user back to the newly updated list of topics (which is what I'm displaying)
Cheers
Erik
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: forwarding a request a second time