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

求助 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条回答 默认 最新

  • threenewbee 2020-09-27 08:06
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
  • ¥15 SQL Server analysis services 服务安装失败
  • ¥15 基于面向对象的图书馆借阅管理系统
  • ¥15 opencv图像处理,需要四个处理结果图