当前位置:首页 » 网页前端 » 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
}
}
}