热门文章
大家都知道 能在Controller/action层获取 HttpServletRequest , 但是这里给大家备份的 是 从代码内部 service层获取HttpServletRequest 工具类。 具体如下:
importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpSession;importorg.springframework.web.context.request.RequestContextHolder;importorg.springframework.web.context.request.ServletRequestAttributes;publicclassContextHolderUtils{publicstaticHttpServletRequestgetRequest(){HttpServletRequestrequest=((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();returnrequest;}publicstaticHttpSessiongetSession(){HttpSessionsession=getRequest().getSession();returnsession;}}