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

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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样