You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@jakarta.apache.org by Petr Suchomel <ps...@itsignet.cz> on 2000/04/11 08:54:53 UTC

Redirect and setting headers

Please help me
I have two problems
    First, is it possible to set headers in JSP page ...like in the servlet API 2.0? method setHeader(String, String).

    Second, i need to redirect from one page to the other.
If I use <jsp:forward> tag, I am forwarded correctly, but in the Explorer command line hangs previous visited link and if I use the refresh button, the previous action is invoked. In servlet API 2.0 is possible to use sendRedirect(String) method, if I use response.sendRedirect in JSP page I get the exception.
Petr

Re: Redirect and setting headers

Posted by Avi Cherry <al...@cafe.net>.
>    First, is it possible to set headers in JSP page ...like in the 
>servlet API 2.0? method setHeader(String, String).
>
>    Second, i need to redirect from one page to the other.
>If I use <jsp:forward> tag, I am forwarded correctly, but in the 
>Explorer command line hangs previous visited link and if I use the 
>refresh button, the previous action is invoked. In servlet API 2.0 
>is possible to use sendRedirect(String) method, if I use 
>response.sendRedirect in JSP page I get the exception.

To set an arbitrary header, use response.addHeader("name", "value")
To do a 'proper' redirect, use:

response.addHeader("Location", "http://someURL");
response.setStatus(response.SC_MOVED_TEMPORARILY);
return;

Of course, you can always do a Refresh type of redirect, but what 
I've demonstrated above is how you switch directly from one URL to 
another without having an intermediate page in between, which is what 
I assume you're looking for.  I don't remember the exact names of the 
headers for doing a Refresh type of redirect, but I do know you can 
leave the status as the default.
jsp:forward does something VERY different. jsp:forward will forward 
the request to a new URL internally (a new JSP request will be 
called, or a new servlet) and display the contents of that new URL 
but NOT redirect your BROWSER to a new URL, thus, if you refresh, it 
will do the same thing as last time, which will do whatever action 
the first page does, then display the second page.

If I'm not making sense, it's because it's too early.
I'm going back to sleep.