Spring MVC
可以直接作为Controller的参数传入:
- @RequestMapping(value = "/test", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
- @ResponseBody
- public Map test(HttpSession session, String otherParam) {
- //TODO
- return null;
- }
其它
要获取HttpSession,只需要获取到HttpServletRequest,然后调用HttpServletRequest的getSession方法
1、注解自动注入
- @Autowired
- private HttpSession session;
- @Autowired
- private HttpServletRequest request;
2、普通类中获取
- HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
- request.getSession();