Michael Donnelly wrote:
>
> Is there a real equivalent to ASP's Response.Redirect in JSP?  I don't want
> to <jsp: forward /> the request for various reasons (full URL, duplicate
> includes, etc).  I just want to send a 302 down to the browser and be done
> with it.
>
> If there's no such beastie, how about some way to write the headers directly
> to the client?  I can build the HTTP/1.1 response myself if necessary.
>
> I can't imagine that kind of basic functionality isn't in JSP, but I haven't
> been able to find anything like it searching the FAQs and what-have-you.  My
> only other option seems to be generating a tiny page with a JavaScript that
> contains a window.location assignment, but it's a little early in the
> lifecycle to resort to that kind of cheese.

I'm pretty sure that any book about JSP describes this:

  <% response.sendRedirect("/thePageYouWantToRedirectTo.jsp"); %>

If the value starts with a slash, as above, it's interpreted as the
absolute path to the page relative to the server, i.e. you have to
include the context-path if you use this in an application with
a different context path than default:

  <% response.sendRedirect(request.getContextPath() +
       "/thePageYouWantToRedirectTo.jsp"); %>

If you can use a path that's relative to the current page, i.e. it
doesn't start with a slash, you don't have to worry about the
context path:

  <% response.sendRedirect("aPageInTheSameDirectory.jsp"); %>

This, as so much else you can use in JSP, is described in the servlet
specification, since JSP is built on top of JSP. I really recommend
that you get one of the numerous books about JSP, but if you don't
want to (for some obscure reason), you should at least read both the
servlet and the JSP specification:

  <http://java.sun.com/products/servlets/>
  <http://java.sun.com/products/jsp/>

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to