Struts 2 Session Management. I am not able to crea

2020-05-02 13:10发布

I am not able to manage Session with Struts2 . If I login successfully and if I click the URL of login again, it again asks for login. I want it to be logged in till timeout doesn't happens.

1条回答
The star\"
2楼-- · 2020-05-02 13:45

The session is already managed in Struts2. If you want to put some object like an user to the session you can use authentication interceptor like this. It checks if an user in session and let the action invoke, otherwise it returns a login result. The user might want to login several times under different accounts, so you should not restrict him/her from doing it. In the JSP you could check the user in session with the if tag using a #session context variable.

<s:if test="#session.user == null">
 <s:a action="login"><s:text name="label.enter"/></s:a>
</s:if>
<s:else>
  <s:a action="logout"><s:text name="label.exit"/></s:a>
</s:else>   
查看更多
登录 后发表回答