File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 63866

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] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Response.sendRedirect() x RequestDispatcher.forward
jQuery in Action, 3rd edition