Aborting the Page Processing
For some custom actions, the processing of the page must stop after
the custom action has been processed. An example is a custom action
that redirects or forwards to another page, such as the JSTL
<c:redirect>
action.
A simple tag handler can throw a
javax.servlet.jsp.tagext.SkipPageException
to
signal to the container that the rest of the page must not be
evaluated. The container respects this no matter how deeply the
custom action is nested within bodies of other actions. To show how
it’s done, here’s a simple tag
handler with the sole purpose of aborting the page processing:
package com.ora.jsp.tags.xmp;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class AbortPageTag extends SimpleTagSupport {
public void doTag( ) throws JspException {
throw new SkipPageException( );
}
}
You could use this feature to, for instance, develop a smart
forwarding action that decides which page to forward to based on
runtime conditions, such as the time of the day, the current user, or
the type of browser accessing the page. After the forwarding call,
throwing the SkipPageException
terminates the
processing of the rest of the page that contains the forwarding
action.
Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.