This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Response.sendRedirect() x RequestDispatcher.forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Response.sendRedirect() x RequestDispatcher.forward" Watch "Response.sendRedirect() x RequestDispatcher.forward" New topic

Response.sendRedirect() x RequestDispatcher.forward

Vinicius Carvalho
Ranch Hand

Joined: Dec 07, 2004
Posts: 61
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

Joined: Jan 10, 2002
Posts: 60794

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
subject: Response.sendRedirect() x RequestDispatcher.forward
Similar Threads
Struts2 - Not forwarding to another action using type="Dispatcher"
accessing Servlet Context Path from servlet filter
Choosing Between Forward and Redirect
Weird Servlet Error
jsp:forward and res.sendRedirect()