JonTom Kittredge wrote:

> 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").
>

In a servlet, or in one of my action methods, I just do a "return" after calling
sendRedirect() or RequestDispatcher.forward() -- it does the trick just fine, because
my dispatching servlet doesn't do anything after the action method returns.  Note that
you don't have to worry about this with <jsp:forward> -- the generated code in effect
does a "page halt" return for you.  In JSP 1.1, you get the ability to signal this type
of thing in your own custom tags as well.


>
> 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
>

Craig McClanahan

===========================================================================
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