m0_48773683
卷铺盖走人
2020-09-26 15:56
采纳率: 100%
浏览 182
已采纳

求助 java.lang.IllegalStateException: getAttribute: 会话已失效.

网页30分钟没操作,session自动失效报的错

九月 22, 2020 7:47:15 上午 org.apache.catalina.session.StandardSession removeAttributeInternal
严重: 会话属性事件侦听器引发异常
java.lang.IllegalStateException: getAttribute: 会话已失效
    at org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1176)
    at org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:115)
    at org.student.listener.AttributeListener.attributeRemoved(AttributeListener.java:47)
    at org.apache.catalina.session.StandardSession.removeAttributeInternal(StandardSession.java:1876)
    at org.apache.catalina.session.StandardSession.expire(StandardSession.java:870)
    at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:648)
    at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:668)
    at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:653)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1483)
    at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:6063)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1676)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1686)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1686)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1654)
    at java.lang.Thread.run(Unknown Source)

九月 22, 2020 7:47:15 上午 org.apache.catalina.session.StandardSession removeAttributeInternal
严重: 会话属性事件侦听器引发异常
java.lang.IllegalStateException: getAttribute: 会话已失效
    at org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1176)
    at org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:115)
    at org.student.listener.AttributeListener.attributeRemoved(AttributeListener.java:47)
    at org.apache.catalina.session.StandardSession.removeAttributeInternal(StandardSession.java:1876)
    at org.apache.catalina.session.StandardSession.expire(StandardSession.java:870)
    at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:648)
    at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:668)
    at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:653)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1483)
    at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:6063)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1676)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1686)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1686)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1654)
    at java.lang.Thread.run(Unknown Source)

这是监听session中attributeRemoved报的错

出错行:

Object attrValue = se.getSession().getAttribute(attrName);

完整代码

package org.student.listener;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

public class AttributeListener implements ServletContextAttributeListener,HttpSessionAttributeListener,ServletRequestAttributeListener{

    @Override
    public void attributeAdded(ServletRequestAttributeEvent srae) {
        String attrName = srae.getName();
        Object attrValue = srae.getServletRequest().getAttribute(attrName);
        System.out.println("新增request对象"+attrName+":"+attrValue);

    }

    @Override
    public void attributeRemoved(ServletRequestAttributeEvent srae) {
        String attrName = srae.getName();
        Object attrValue = srae.getServletRequest().getAttribute(attrName);
        System.out.println("删除request对象"+attrName+":"+attrValue);

    }

    @Override
    public void attributeReplaced(ServletRequestAttributeEvent srae) {
        String attrName = srae.getName();
        Object attrValue = srae.getServletRequest().getAttribute(attrName);
        System.out.println("更改request对象"+attrName+":"+attrValue);

    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        String attrName = se.getName();
        Object attrValue = se.getSession().getAttribute(attrName);
        System.out.println("新增Session对象"+attrName+":"+attrValue);

    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent se) {
        String attrName = se.getName();
        Object attrValue = se.getSession().getAttribute(attrName);
        System.out.println("删除Session对象"+attrName+":"+attrValue);

    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent se) {
        String attrName = se.getName();
        Object attrValue = se.getSession().getAttribute(attrName);
        System.out.println("更改Session对象"+attrName+":"+attrValue);

    }

    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        String attrName = scae.getName();
        Object attrValue = scae.getServletContext().getAttribute(attrName);
        System.out.println("新增application对象"+attrName+":"+attrValue);

    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        String attrName = scae.getName();
        Object attrValue = scae.getServletContext().getAttribute(attrName);
        System.out.println("删除application对象"+attrName+":"+attrValue);

    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        String attrName = scae.getName();
        Object attrValue = scae.getServletContext().getAttribute(attrName);
        System.out.println("更改application对象"+attrName+":"+attrValue);

    }

}

求助大佬

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

相关推荐