tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Kilbride" <>
Subject Re: How to forward with new request/query string?
Date Fri, 20 Jul 2001 03:59:28 GMT
Hi Erin,

You can't change the original request (at least, I don't think you
can...) -- but you can add info to the request before forwarding it on to
your jsp page. Just add the extra info to the query string of the jsp your
forwarding to:

String location = "myForward.jsp?foo=bar&baz=1";
RequestDispatcher rd = request.getRequestDispatcher(location);
rd.forward(request, response);

The parameters foo and baz will now be available in myForward.jsp, along
with all the original request params. If foo and baz exist in the original
request, calling request.getParameter() will return the newly set value and
calling request.getParameterValues() will return all values for that

You can also store info in the request object using setAttribute() and
retrieve them in the jsp by using getAttribute():

(in servlet)
request.setAttribute("key", value);

(in jsp -- if the value is a String object)
String value = (String)request.getAttribute("key");

Notice that you have to cast the object back to the correct type in your

Hope this helps.


----- Original Message -----
From: "Erin Lester" <>
To: <>
Sent: Thursday, July 19, 2001 1:36 PM
Subject: How to forward with new request/query string?

> I was wondering how you go about transferring control from a servlet to
> another page (in this case a jsp page) before committing the response.  I
> need to send request variables to this new page.  I've tried using a
> request dispatcher, but I believe that this just sends the request that
> the servlet got and not a new one with the querystring values (which are
> appended to the url I want to forward to) in it.
> Can someone tell me how to do this?  Also, what's the difference between
> sendRedirects, dispatcher forwards, etc. ?  and is there any way to
> transfer control to another page and have the user's location bar reflect
> the address of the new page?
> Any help would be appreciated!
> - Erin

View raw message