Gabriel J Zimmerman wrote:
> Hi everyone,
>
> I had some questions about URL redirection using JSP Custom tags.
> Basically I want to create a conditional tag that writes a page if a
> condition is met and if not redirects to another page.
>
> Supposedly if the page to redirect to is a jsp page, you can use the
> pageContext.forward("my_other_jsp.jsp"); command. However, this is
> usually used within a the jsp page itself and "return;" should be called
> therafter. Does this mean I cannot use the PageContext.forward() method
> within a JSP Tag?
>
I built a <struts:forward> tag that does forwarding via pageContext.forward() into
the custom tag library in the Struts framework <http://jakarta.apache.org/struts>.
The secret is that you want to tell the JSP system to skip the rest of the current
page, which you do by returning an appropriate value from the doEndTag() method.
So, the guts of your logic can be in the doEndTag() method:
public int doEndTag() throws JspException {
if (... not forwarding ... )
return (EVAL_PAGE);
String url = ... the URL to forward to ...
pageContext.forward(url);
return (SKIP_PAGE);
}
The same kind of trick is needed if you are doing a response.sendRedirect() call
instead.
>
> Thanks in advance,
>
> Gabe Zimmerman
>
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets