在spring的业务层获取request,response

1.直接通过controller层获取到传输到业务层
2.SpringMVC提供的RequestContextHolder可以直接获取
代码:
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
// RequestContextHolder.getRequestAttributes();
//从session里面获取对应的值
String str = (String) requestAttributes.getAttribute("name",RequestAttributes.SCOPE_SESSION);

HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest();
HttpServletResponse response = ((ServletRequestAttributes)requestAttributes).getResponse();

posted @ 2018-10-10 22:30  山神笔记  阅读(954)  评论(0编辑  收藏  举报