views:

1588

answers:

1

Hi All,

I want to learn how session management is being done in Spring web MVC. Do you know any free tutorial on how is it being done?

I am thinking of similar sample applicatin such as BookStore or Shopping cart applications that I have done using basic servlets and JSP.

Kindly advise me how is it done and make it done the proper way in Spring Framework.

Thanks to all.

A: 

Hi Skaffman,

I basically have this confusion on how to implement session management in Spring?

Is this how spring session management is properly done in Spring? This is where we get session object from request and then properly set or remove attributes?

public class LoginController extends SimpleFormController {

public ModelAndView onSubmit(HttpServletRequest request,
        HttpServletResponse response, Object command, BindException errors) {

    HttpSession session = request.getSession();
    User user =
        (ArrayList)session.getAttribute("userInfo");
    if (user == null) {
        user = new ArrayList();
        session.setAttribute("userInfo", user);
    }

    //other code here
    return new ModelAndView(new RedirectView(getSuccessView()));
}
}

I got confused actually when I have read about session scope beans in the spring documents? I am not sure if they are used in Spring Web MVC.

Kindly enlighten me on this. Thank you

Rex Mercardo