我有一個關於領域認證的問題,其中glassfish創建多個http會話。這裏有一個例子Glassfish在領域認證中創建多個http會話
web.xml中:
<security-constraint>
<web-resource-collection>
<web-resource-name>AllPages</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>FileRealm</realm-name>
</login-config>
<security-constraint>
與GlassFish的web.xml:
<security-role-mapping>
<role-name>user</role-name>
<group-name>users</group-name>
</security-role-mapping>
的login.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Page</title>
</head>
<body>
<p>You have successfully logged into the application.</p>
<a href="./home.jsp">go to home</a>
</body>
</html>
SessionListener:
@WebListener公共類SessionListener實現 HttpSessionListener {
公共無效sessionCreated(HttpSessionEvent爲arg0){
的System.out.println( 「會話創建ID:」。+ arg0.getSession()的getId());
}公共無效sessionDestroyed(HttpSessionEvent爲arg0){
System.out.println("Session destroyed id:"+arg0.getSession().getId());
}
}
當我進行身份驗證,GlassFish中創建一個新的會話:
信息:會話創建ID:29c5d904db0e40b9cfbdac40aa5e
當我點擊「轉到主頁」鏈接或刷新頁面,GlassFish的創建另一個HTTP會話:
INFO:會話創建ID:2a67270137e38c150bf3690e2e46
而且我還注意到,GlassFish的永不毀滅第一次創建會話。
感謝您的幫助