If you use a JSP extension tag instead of a bean, you could return SKIP_PAGE from the
doEndTag() method to indicate that the rest of the page should be skipped. Using the
tag also gives you easy access to the current output stream and to the PageContext
object which would otherwise have to be passed into the bean via properties (or
perhaps a straight method invocation). The result would be a tag that's very similar
to the <jsp:forward> tag, but it could be customized to suit you needs.
Brien Voorhees wrote:
> Looking at the java file generated from one of my jsp's that contains a
> <jsp:forward> directive reveals the following code :
>
> public void _jspService(HttpServletRequest request, HttpServletResponse
> response)
> {
> ... stuff omitted ...
> PageContext pageContext =
>JspFactory.getDefaultFactory().getPageContext(this, request, response, null, true,
>5120, true);
> out = pageContext.getOut();
> ... stuff omitted ...
> // start of <jsp:forward> logic
> if( <some expression deciding whether you want to forward> )
> {
> out.clear(); // clear current output buffer
> pageContext.forward("main.jsp"); // forward to specified page
> return; // after main.jsp executes we don't want to continue processing
>the rest of the current page, so return
> }
>
> If you wanted to pass the pagecontext object to your bean it could implement the
>forwarding internally. The problem is that when your bean's method returned (after
>internally indirectly executing the other jsp's service method) the current page
>would need to know that it should return instead of continuing to output/process the
>rest of the (now incorrect) page. Possibly a better approach would be to have your
>bean return a value indicating that a forwarding should occur. For example (please
>ignore any improper syntax):
> <jsp:usebean id="loginBean" ....>
> blah blah
> <%
> if(loginBean.authFailed())
> {%>
> <jsp:forward page="failed.jsp">
> <%}%>
>
> blah blah rest of page
>
> If you want the bean to have more control over what page is forwarded to, you could
>try something more like :
>
> <%
> String forwardTo = loginBean.authenticate();
> %>
> <jsp:forward page= <%=forwardTo%> >
>
> Hope that helps,
> Brien Voorhees
>
===========================================================================
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