如何检查用户是否使用Struts 2登录 [英] How to check if user is logged in with Struts 2

查看:150
本文介绍了如何检查用户是否使用Struts 2登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法管理与Struts2的会话.

I am not able to manage a session with Struts2 .

如果我成功登录,并且再次单击登录URL,则会再次要求登录.

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 untill timeout doesn't happens.

推荐答案

会话已在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>   

这篇关于如何检查用户是否使用Struts 2登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆