zoukankan      html  css  js  c++  java
  • Tomcat的shezhisession超时的几种方式

    Tomcat的会话超时可以在多个级别上设置:tomcat实例级别、Web应用级别、servlet级别以及运行时Context代码级别。 较低级别的设定会覆盖较高级别的设定。

    Tomcat可以在以下几个地方设置session超时:

    1 Web容器级别

    在conf/web.xml中

    Xml代码 
    1. <!-- ==================== Default Session Configuration ================= -->
    2. <!-- You can set the default session timeout (in minutes) for all newly -->
    3. <!-- created sessions by modifying the value below. -->
    4. <session-config>
    5. <session-timeout>30</session-timeout>
    6. </session-config>
    <!-- ==================== Default Session Configuration ================= -->
      <!-- You can set the default session timeout (in minutes) for all newly   -->
      <!-- created sessions by modifying the value below.                       -->
    
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>

    这里是以分钟为单位的,默认是30分;

    2 webapp级别

    在webapp中的 WEB-INF/web.xml

    Xml代码 
    1. <!-- 配置Session失效时间 -->
    2. <session-config>
    3. <session-timeout>30</session-timeout>
    4. </session-config>
            <!-- 配置Session失效时间 -->
            <session-config>
                    <session-timeout>30</session-timeout>
            </session-config>

    也是以min为单位;

    3 应用程序代码中:硬编码

    Java代码 复制代码 收藏代码
    1. session.setMaxInactiveInterval(30*60);//以秒为单位
    session.setMaxInactiveInterval(30*60);//以秒为单位

    优先级,越细粒度优先级越高,也就是3>2>1

    4 还要一种配置,但现在比较少见了,因为需要将Context配置在server.xml里:

    这就是修改conf/server.xml

    Xml代码 
    1. <Context path="/test" docBase="/home/httpd/html/test"
    2. defaultSessionTimeOut="3600" isWARExpanded="true"
    3. isWARValidated="false" isInvokerEnabled="true"
    4. isWorkDirPersistent="false"/>
    <Context path="/test" docBase="/home/httpd/html/test"
        defaultSessionTimeOut="3600" isWARExpanded="true"
        isWARValidated="false" isInvokerEnabled="true"
        isWorkDirPersistent="false"/>

    单位为秒

    附:

    重启时保持会话
    在关闭Tomcat实例/取消Web应用部署时,缺省会把当前的活动会话保存到硬盘上,并在重启启动/部署 时在把会话从硬盘上加载到内存中。
    文件保存在各目录下的SESSIONS.SER中。有时可能会话中保存了敏感信息,或者不希望使用这个特 性,可以配置Context.xml文件关闭这个选项。
    配置 manager.pathname == ""即可,形如:
    <Manager pathname="" />

     
    大家好: 很高兴自己在不断学习的过程中,积累知识和经验。也能够为了正在学习的网友们提供好的资料,一起学习,一起努力。成就自己的梦想.............
  • 相关阅读:
    MySQL监控、性能分析——工具篇
    [转载]Error -27796: Failed to connect to server
    Tomcat最大连接数问题
    Jconsole的使用
    通过jconsole监控tomcat JVM 内存、线程、CPU
    Tomcat部署web项目
    tomcat部署web项目的3中方法
    在linux下修改oracle的sys和system的密码和用户解锁
    静默安装oracle11G
    Linux 卸载Oracle 11G
  • 原文地址:https://www.cnblogs.com/su5012-lingyao/p/5133923.html
Copyright © 2011-2022 走看看