我在apache-tomcat-6.0.30\conf\web.xml中设置为1分钟,1分钟中却还能从session中取值,为什么呢?
<!-- session过期时间是这样设置的 -->
    <session-config>
        <session-timeout>1</session-timeout>
    </session-config>//这样放进值
ActionContext.getContext().getSession().put("xxx",xxx);//然后我是这样取session值的
ActionContext.getContext().getSession().get("xxx");

解决方案 »

  1.   

    设置session的过期时间和struts2完全没关系,我想原因可能就是你在这个20分钟内有用过这个sessoin
      

  2.   

    那设置时间是在WEB-INF中的web.xml设置的
      

  3.   

    而不是LZ 说的tomcat下设置
      

  4.   

    建议LZ用session.setMaxInactiveInterval(50000);试一下
    setMaxInactiveInterval设置的是当前会话的失效时间,不是整个web的时间,单位为以秒计算。session-timeout元素用来指定默认的会话超时时间间隔,以分钟为单位。
      

  5.   

    应该在你的项目下面的web.xml
    而不是tomcat的
      

  6.   

    谢谢各位!
    现在有个问题,就是ActionContext.getContext().getSession().put("xxx",xxx); 放进一个值xxx,
    然后另外一个用户登录,也通过ActionContext.getContext().getSession().put("xxx",xxx); 又放进一个session值,因为名称是一样的,会不会将之前的session踢出?不知道我这想法 对不对?
      

  7.   

    不会的。第一个问题应该是在tomcat的web.xml中设置,
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>
      

  8.   

    我用的是在web.xml中的配置<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee,
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      
       <listener>
      <listener-class>
       org.springframework.web.context.ContextLoaderListener
       </listener-class>
    </listener>

       <filter> <!--定义核心Filter FilterDispatcher -->
    <filter-name>struts2</filter-name> <!-- 定义核心Filter的名称 -->
    <filter-class> <!--定义核心Filter的实现类 -->
    org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name><!--核心Filter的名称 -->
    <url-pattern>/*</url-pattern><!--使用该核心Filter过滤所有的Web请求 -->
    </filter-mapping>
    <jsp-config>   
       <session-config>   
        <session-timeout>30</session-timeout>   
       </session-config>   
    </jsp-config>  

    </web-app>
      

  9.   

    正解,
    销毁这个session
    http://heisetoufa.iteye.com/blog/227194