當前位置:首頁 » 網頁前端 » webxmlsession不過期
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

webxmlsession不過期

發布時間: 2022-04-02 11:58:54

『壹』 session什麼時候會失效時間

session-timeout(web.xml)元素與session.setMaxInactiveInterval()函數

a) web app server中,如websphere里可以設置超時時間為30分鍾

b)在web.xml中的session-config配置
session-timeout元素(WEB.XML文件中的元素)用來指定默認的會話超時時間間隔,以分鍾為單位。該元素值必須為整數。如果 session-timeout元素的值為零或負數,則表示會話將永遠不會超時。如:

<session-config>
<session-timeout>30</session-timeout>
</session-config>
//30分鍾

setMaxInactiveInterval設置的是當前會話的失效時間,不是整個web的時間,單位為以秒計算。如果設置的值為零或負數,則表示會話將永遠不會超時。常用於設置當前會話時間。
c) 在程序中手動設置
java 代碼

session.setMaxInactiveInterval(30 * 60);

『貳』 java web! httpsession失效的三種方式是什麼

(1)在主頁面或者公共頁面中加入:session.setMaxInactiveInterval(900);參數900單位是秒,即在沒有活動15分鍾後,session將失效。
這里要注意這個session設置的時間是根據伺服器來計算的,而不是客戶端。所以如果是在調試程序,應該是修改伺服器端時間來測試,而不是客戶端。
(2)也是比較通用的設置session失效時間的方法,就是在項目的web.xml中設置
<!-- 設置session失效,單位分 -->
<session-config>
<session-timeout>1</session-timeout>
</session-config>
(3)直接在應用伺服器中設置,如果是tomcat,可以在tomcat目錄下conf/web.xml中找到<session-config>元素,tomcat默認設置是30分鍾,只要修改這個值就可以了。

『叄』 怎麼設置不過期的session

方法/步驟

方法一:web app server中,如websphere里可以設置超時時間為30分鍾。

方法二:在web.xml中的session-config配置
session-timeout元素(WEB.XML文件中的元素)用來指定默認的會話超時時間間隔,以分鍾為單位。該元素值必須為整數。如果 session-timeout元素的值為零或負數,則表示會話將永遠不會超時。如:
<session-config> <session-timeout>30</session-timeout></session-config> //30分鍾

方法三:setMaxInactiveInterval設置當前會話時間
setMaxInactiveInterval設置的是當前會話的失效時間,不是整個web的時間,單位為以秒計算。如果設置的值為零或負數,則表示會話將永遠不會超時。常用於設置當前會話時間。該優先順序要比方法三中的優先順序高。

方法四:session中保存一個bean或者map,裡面存儲上相應的過期時間,一旦過期,remove掉。
方法四可以通過一個線程去掃描,如果時間帶了,線程自動清除,或者用的時候進行判斷,用過後進行remove,如果使用線程自動remove,可以使用spring的線程池

『肆』 關於structs2 web.xml文件的session-config配置後失效時間的問題

30分鍾後session會失效嗎?
不會失效
還是說如果30分鍾該用戶一直沒有操作,session才會失效,原理是什麼?
session的一個屬性 記錄了用戶的最後一次訪問session的時間lastAccessedTime
如下是servlet規范原文
In the HTTP protocol, there is no explicit termination signal when a client is no longer active. This means that the only mechanism that can be used to indicate when a client is no longer active is a time out period.

The default time out period for sessions is defined by the servlet container and can be obtained via the getMaxInactiveInterval method of the HttpSession interface. This time out can be changed by the Developer using the setMaxInactiveInterval method of the HttpSession interface. The time out periods used by these methods are defined in seconds. By definition, if the time out period for a session is set to -1, the session will never expire. The session invalidation will not take effect until all servlets using that session have exited the service method. Once the session invalidation is initiated, a new request must not be able to see that session.

The getLastAccessedTime method of the HttpSession interface allows a servlet to determine the last time the session was accessed before the current request. The session is considered to be accessed when a request that is part of the session is first handled by the servlet container.

『伍』 在web.xml下設置session超時不起作用,為什麼

你好,這是servlet3.0里的新規范,我簡單的說一下:
servlet
3.0規范實施前tomcat的會話跟蹤用兩種方法:cookie和帶jsessionid參數的重寫url。

tomcat
7中的url重寫方法不再是強制性的,並加入一個新的會話跟蹤方法基於ssl會話。就這些。

『陸』 java web為什麼我的session過期時間設為永不過期,瀏覽器session還是會過期

用cookie,把失效時間設置很長或者永不過期

『柒』 web應用中session的壽命問題

配置文件設的,有:
<cache-policy-conf>
<min-capacity>50</min-capacity>
<max-capacity>1000000</max-capacity>
<overager-period>300</overager-period>
<max-bean-age>600</max-bean-age>
<resizer-period>400</resizer-period>
<max-cache-miss-period>60</max-cache-miss-period>
<min-cache-miss-period>1</min-cache-miss-period>
<cache-load-factor>0.75</cache-load-factor>
</cache-policy-conf>Top

關於有狀態會話BEAN的生命周期很特別,描述如下:
1:不存在狀態---(client調用create())(容器調用Class.newInstance(),setSessionContext (),ejbCreate())--->進入方法就緒狀態(此時可以為client服務)--->如果超時則容器將其銷毀,回到不存在狀態。
--->如果伺服器要節省資源或遇到新事務開啟,則釋放資源,實例打回到不存在狀態。序列化實例欄位。(容器調用ejbPassivate()掛起)
--->事務等結束,重新找會資源,反序列化實例欄位。建立一個新的BEAN實例(容器調用ejbActivate()激活)
--->容器調用ejbRemove()或客戶顯示調用remove()也會將BEAN打回到不存在狀態。BEAN生命周期結束。
所以,雖然客戶沒有顯示調用remove(),但發生以情況都會將bean回收。

『捌』 session 不設置過期時間,默認是多少

這是tomcat中web.xml默認的配置

<!--====================DefaultSessionConfiguration=================-->
<!--(inminutes)forallnewly-->
<!--.-->

<session-config>
<session-timeout>30</session-timeout>
</session-config>

『玖』 java web項目中web.xml中設置的session-timeout時間,到底是不是頁面不刷新的最大時間求高人

session.TimeOut是指session變數生存時間的長短,伺服器默認是20分鍾,例如登錄成功用session("uslogin")作為登錄標識,那麼session("uslogin")的timeout是20分鍾,當你在超過20分鍾沒有刷新或重新打開頁面,則session過期失效,這樣又要重新登錄。所以可以把session.TimeOut=60即1小時;server.ScriptTimeout這個指腳本執行時間

『拾』 java web.xml設置session過期時間為15分鍾,超時卻不會過期

你可以試試這么做

web.xml
<listener>
<listener-class>
com.listener.SessionListener
</listener-class>
</listener>
<session-config>
<session-timeout>1</session-timeout>
</session-config>

java
public class SessionListener implements HttpSessionListener{

public void sessionCreated(HttpSessionEvent event) {
HttpSession ses = event.getSession();
String id=ses.getId()+ses.getCreationTime();
SummerConstant.UserMap.put(id, Boolean.TRUE); //添加用戶
}

public void sessionDestroyed(HttpSessionEvent event) {
HttpSession ses = event.getSession();
String id=ses.getId()+ses.getCreationTime();
synchronized (this) {
SummerConstant.USERNUM--; //用戶數減一
SummerConstant.UserMap.remove(id); //從用戶組中移除掉,用戶組為一個map
}
}
}