Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get Session Object in Spring MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.81k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: