Hello Friends, we need the session object to maintain the session in the web applications. we have to get the session object in Spring MVC by the following method:-
1:- Put the Session object with the method parameter. Session Object is declared as method parameter inside the Controller's method.
@RequestMapping(value="/handleRequest",type=RequestMethod.POST)
public ModelAndView handleRequest(HttpServletRequest request,HttServletResponse response ,HttpSession session)
{
session.setAttribute("message" , "It is simple to get access to HttpSession "); //to set the session attribute
return new ModelAndView("success");
}
2:- Get the Session Object with the help of HttpServletRequest object
@RequestMapping(value="/handleRequest",type=RequestMethod.POST)
public ModelAndView handleRequest(HttpServletRequest request,HttServletResponse response )
{
HttpSession session=request.getSession();
session.setAttribute("message" , "It is simple to get access to HttpSession "); //to set the session attribute
return new ModelAndView("success");
}
0 Comment(s)