2016-07-15 97 views
1

我是一個嘗試通過j_security_check的幫助創建登錄頁面來學習jsp的初學者。J_security_check會話沒有結束

在以下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> 

一旦進入正確的憑證後,但是,它只是停留在「登錄」模式,當我重新啓動服務器時,它不提示我再次登錄。我一直在使用

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出了錯)

,但他們都似乎沒有工作。所以我的問題是如何註銷?我的結構中有沒有問題?所有的幫助表示讚賞。

回答

0

登錄頁面簡單地更改爲實際登錄頁面:

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