RenegadePISTA 2018-09-20 10:14 采纳率: 100%
浏览 1564
已结题

Exception in thread "Timer-0" java.lang.IllegalStateException: No thread-bound request found

@RequestMapping("/sendVericationCode.action")
@ResponseBody
public AjaxJson sendVericationCode(){
String mobile = (String)session.getAttribute("mobile");
AjaxJson ajaxJson = JuheDemo.getRequest2(mobile);
if(ajaxJson.isSuccess()==true) {
session.setAttribute("vericationcode",ajaxJson.getMsg());
request.setAttribute("mobile",mobile);
//timer定时任务加一个定时器,2分钟后删除session

       try {final   Timer timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                session.removeAttribute("vericationcode");
                timer.cancel();
                System.out.println("显示"+session.getAttribute("vericationcode"));
            }
        }, 2*60*1000);

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }

    }
    ajaxJson.setMsg("错误啦!!!!");
    return ajaxJson;
}****

报错:Exception in thread "Timer-0" java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2018-09-24 12:20
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动