非action层获取HttpServletRequest

1.如何在一个线程的任何地方(即其他层)获取 HttpServletRequest

In every request, the DispatcherServlet binds the current HttpServletRequest to a static ThreadLocal object in the RequestContextHolder. You can retrieve it when executing within the same Thread with

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();

 

posted @ 2015-08-29 14:56  predisw  阅读(160)  评论(0编辑  收藏  举报