2

我正在使用带有 apache tomcat 的 auth-method FORM 来对用户进行身份验证。我正在使用默认的 j_security_check 操作。

如果用户已登录,我必须显示退出链接。否则是一个登录链接。如何检查用户是否已登录?

另外,如何注销用户?

4

3 回答 3

7

您可以使用HttpServletRequest.getUserPrincipal()并检查它以查找已登录的用户。

于 2012-07-29T20:57:43.577 回答
1

登录状态与HttpServletRequest.getUserPrincipal()返回非空的状态相同。

于 2012-07-30T01:13:44.357 回答
0
if(request.authenticate(response)){
    System.out.println("The User is Authenticated");
}else{
   System.out.println("The User is not Authenticated");
}

在您的 JSP 或 Servlet 中使用此代码。

于 2022-01-24T11:10:47.763 回答