且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查用户是否使用Struts 2登录

更新时间:2023-11-30 22:03:28

会话已在Struts2中进行管理.

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.

它检查会话中是否有用户,并让该操作调用,否则返回 login 结果.

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.

在JSP中,您可以使用 #session 上下文变量,使用 if 标记检查会话中的用户.

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>