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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access