我使用 Struts2 框架。在 jsp 中,我在我的项目中显示了一个登录框,当用户单击登录按钮时,我设置了一个名为“loggedin”的 cookie,并在 Action 类中将其值设置为“true”。
然后返回“成功”将再次加载此登录页面。
在登录页面:
<body>
<%
Cookie cookie[] = request.getCookies();
for( c : cookie )
{
if( c.getName().equals("loggedin") )
{
if( !c.getValue().equals("true") )
{
%>
//show login form here.
<%
}//end inner if
else //if cookie "loggedin" value is "true"
{
%>
//show username/profile picture/logout button here
<%
}//end else
}//end outer if
}/end for loop
%>
</body>
我有问题。当我单击登录表单中的登录按钮时,会设置一个 cookie 并重新加载页面。但是,在我手动重新加载页面之前,仍然显示登录表单,而不是用户名/个人资料图片。
- 我该如何解决这个问题?
- 我认为这不是检查是否登录的正确方法。有人可以告诉我如何以另一种方式检查吗?