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

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

相关推荐