Menu

Spring user session control sample ?

2004-07-23
2004-07-23
  • PrettyHandling

    PrettyHandling - 2004-07-23

    Hi,

       I need an workable example of user session management using Spring. For example,

    <logic:notPresent name="accountBean" scope="session">
      <html:link page="/shop/signonForm.shtml">
    sign-in</html:link>
    </logic:notPresent>
    <logic:present name="accountBean" scope="session">
      <logic:notEqual name="accountBean" property="authenticated" value="true" scope="session">
            <html:link page="/shop/signonForm.shtml">
    sign-in</html:link>
      </logic:notEqual>
    </logic:present>

    <logic:present name="accountBean" scope="session">
      <logic:equal name="accountBean" property="authenticated" value="true" scope="session">
          <html:link page="/shop/signoff.shtml">
       sign-out</html:link>
      </logic:equal>
    </logic:present>

    the above code is taken from JPetstore 4.

    Appreciate if anyone can provide an example. Thanks !

    regards,
    PrettyHandling

     
    • Matt Raible

      Matt Raible - 2004-07-23

      It looks like you're simply trying to port your Struts <logic> tags to Spring.  You could use JSTL's "core" tag. 

      <old>
      <logic:notPresent name="accountBean" scope="session">
      <html:link page="/shop/signonForm.shtml">
      sign-in</html:link>
      </logic:notPresent>
      <logic:present name="accountBean" scope="session">
      <logic:notEqual name="accountBean" property="authenticated" value="true" scope="session">
      <html:link page="/shop/signonForm.shtml">
      sign-in</html:link>
      </logic:notEqual>
      </logic:present>
      </old>

      <new>
      <c:if test="${sessionScope.accountBean == null}">
          <a href="<c:url value='/shop/signonForm.shtml'/>">sign-in</a>
      </c:if>
      <c:if test="${sessionScope.accountBean != null}">
         <c:if test="${sessionScope.accountBean.authenticated != 'true'>
             <a href="<c:url value='/shop/signonForm.shtml'/>">
             sign-in</a>
         </c:if>
      </c:if>
      </new>

      The "sessionScope" part is optional - the tag will look through all scopes if it's not specified.

      Matt

       

Log in to post a comment.

MongoDB Logo MongoDB