RenegadePISTA 2018-09-21 03:27 采纳率: 100%
浏览 3727
已结题

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

  • zqbnqsdsmd 2018-09-22 13:52
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办