This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
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

Response.sendRedirect() x RequestDispatcher.forward

 
Vinicius Carvalho
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there! As far as I know (and I bet I'm wrong

Redirect adds a Header to the response (I guess Location) and the browser then redirects the user to the new location right?
Also forward can be used only within the same context.

Now, I have a server running Jetty and need to redirect the user to a tomcat machine, but I need to add some headers and attributes to the request, how can I do that? With redirect it does not work, and with forward (well, not the same context...)

Best Regards
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The request in which you are about to send a response containing the redirect header will go out of scope as soon as the response is dispatched.

So there really is no request to which to can add anything.

You can put query parameters on the redirect URL, which will be turned into request parameters when the browser initiates the redirected request, but that's about the extent of control that you have.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic