Brien Voorhees wrote:

> When a user object doesn't exist already in the session I want to forward
> the user to the login page.  I'm trying to do this by putting the forward
> tag within the context of the useBean tag but it doesn't seem to work.
> Here's what is in the jsp :
>
> <jsp:useBean id="bapiContext" scope="session"
> class="proto.bapi.EmptyBapiContext" type="proto.bapi.BapiContext">
>    <jsp:forward page="/login.jsp"/>
> </jsp:useBean>
>

Per the JSP spec, the thing you can put inside the <jsp:useBean> ... </jsp:useBean>
combination is <jsp:setProperty> elements.  Even if the compiler generated the code
for the forward, it would probably generate an unconditional forward, rather than a
conditional one.

I solve this sort of problem by coding the equivalent scriptlet:

<%
  proto.bapi.BapiContext bapiContext =
    (proto.bapi.BapiContext) session.getValue("bapiContext");
  if (bapiContext == null) {
%>
    <jsp:forward page="/login.jsp"/>
<%
  }
%>

In a JSP 1.1 environment (with custom tag libraries), it's also possible to create
a variation on the <jsp:useBean> element that has semantics like what you tried
here.

Craig McClanahan

===========================================================================
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

Reply via email to