Paul Allton wrote:

> > sendRedirect("http://www.here.com/gothere.html");
> >
> > would result in the page going to gothere.html.
> >
> > Is there a way to say 'ok right now send a redirect to X and don't bother
> > processing anything else'?
>
> Basically, directly after the sendRedirect do a "break;" ... some people
> will no doubt argue that this isnt terribly structured (and I'm one of them)
> .. but it does work.
>
> The preferable solution would be to write code more carefully so that it
> naturally drops out without causing any ill effects.

I handled this situation by creating a special exception, PageHaltException, that I
throw after a sendRedirect() or a forward(). My top-level servlet service method
catches this exception and ignores it (I've taken a page from Craig M's book, and
am using a single servlet as a dispatcher to my page "controllers").

This technique ensures that right thing happens when I do a redirect (or forward)
from deep in my servlet code. This is in my regular servlet code (as opposed to my
JSP pages), since I don't put complex code in JSP. It would be kind of messy to use
this technique in JSP, unless you created your own JspPage class, which is not
something to do lightly.

Yours, JonTom

    JonTom Kittredge
    ITA Software, Inc
    Cambridge, Massachusetts

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to