J_security_check会话未结束

时间:2016-07-15 16:58:39

标签: jsp security session web.xml j-security-check

我是一个初学者,试图通过在j_security_check的帮助下创建一个登录页面来学习jsp。

web.xml的以下代码中,您可以看到受保护文件夹中的所有内容都需要您登录才能访问它。

<welcome-file-list>
    <welcome-file>protected/home.jsp</welcome-file>
</welcome-file-list>

<security-constraint>
    <display-name>Security Constraint</display-name>
    <web-resource-collection>
        <web-resource-name>Protected Area</web-resource-name>
        <url-pattern>/protected/*</url-pattern>
        <http-method>DELETE</http-method>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name> manager </role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>Example Form-Based Authentication Area</realm-name>
    <form-login-config>
        <form-login-page>/protected/home.jsp</form-login-page>
        <form-error-page>/error.jsp</form-error-page>
    </form-login-config>
</login-config>
<security-role>
    <description> An administrator </description>
    <role-name> manager </role-name>
</security-role>

然而,在输入正确的凭证一次后,它只会停留在&#34;登录&#34;模式,当我重新启动服务器时,它不会提示我再次登录。我尝试过使用

HttpSession session=request.getSession(); session.invalidate();

以及

<% request.getSession().invalidate(); request.getSession(false); %>

以及How to properly logout of a Java EE 6 Web Application after logging in上的答案(除了最后一个,因为FacesContext出了问题)

但它们似乎都不起作用。所以我的问题是如何退出?我的结构有什么问题吗?感谢所有帮助。

1 个答案:

答案 0 :(得分:0)

只需将登录页面更改为实际登录页面:

<form-login-config> <form-login-page>/login.jsp</form-login-page> <form-error-page>/error.jsp</form-error-page> </form-login-config>

相关问题