Spring MVC - Session differences

梦想与她 提交于 2019-12-05 20:07:51

Basically there is no diffrerence between the session object injected into a Spring MVC controller:

@RequestMapping(value = "/somepath", method = RequestMethod.POST)
@ResponseBody
public JsonResponse someMethod (HttpSession session)
{
 // play with session attributes
}

And the session object retrieved from the HttpServletRequest:

@RequestMapping(value = "/somepath", method = RequestMethod.POST)
@ResponseBody
public JsonResponse someMethod (HttpServletRequest request)
{
  Session session = request.getSession();
  // You are playin with the same session attributes.
}

The former style just provide you with a facility to get the contextual HttpSession object by injecting it as a controller argument so that Spring takes care of the all the dirty stuff for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!