spring 怎么获取response
1个回答
展开全部
1.最简单方式:参数
[java] view plain copy
@RequestMapping("/test")
@ResponseBody
public void saveTest(HttpServletRequest req, HttpServletResponse resp){ }
2.加入监听器,然后再controller里面获取
(1)web.xml相应位置插入
[html] view plain copy
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
[java] view plain copy
HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse resp = ((ServletWebRequest)RequestContextHolder.getRequestAttributes()).getResponse();
[java] view plain copy
@RequestMapping("/test")
@ResponseBody
public void saveTest(HttpServletRequest req, HttpServletResponse resp){ }
2.加入监听器,然后再controller里面获取
(1)web.xml相应位置插入
[html] view plain copy
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
[java] view plain copy
HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse resp = ((ServletWebRequest)RequestContextHolder.getRequestAttributes()).getResponse();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询