Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

forwarding a request a second time

 
Sven Anderson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sven Anderson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic