General Servlet/Java Question regarding http redirects

When issuing a response.sendRedirect(url) from a servlet or a useBean, how do you all deal with what happens in the currently processing class from that point on? It seems that processing continues within whatever method issued the redirect.

Do you just do exception handling after a sendRedirect() to make sure that no other code is processed within that class/method?

Thanks,
Ian.

0
2 comments

You should not do anything after the redirect. Coding after the
redirect will only bring you heartache.

Norris Shelton
Sun Certified Java Programmer




Ian Zabel wrote:

>When issuing a response.sendRedirect(url) from a servlet or a useBean, how do you all deal with what happens in the currently processing class from that point on? It seems that processing continues within whatever method issued the redirect.
>
>Do you just do exception handling after a sendRedirect() to make sure that no other code is processed within that class/method?
>
>Thanks,
>Ian.

>

0

I agree with that. But, in practice, that's tough to avoid, especially if the redirect happens within a useBean call from a JSP. It seems after the redirect has been called, the method returns and the JSP continues to process. (although the browser never sees it)

In our app, whenever we do a redirect, we throw an exception that is caught in every JSP and handled by doing nothing. This means that every JSP we have must be wrapped in a try/catch (from included files), which doesn't seem very nice.

Just wondering if there's a better way of handling this.


...
We're not using any standard framework such as Struts. It's basically all homegrown code that started in 1999 or so.

0

Please sign in to leave a comment.