Results 1 to 4 of 4

Thread: session management in Spring MVC 3.0

  1. #1
    Join Date
    Oct 2009
    Posts
    21

    Default session management in Spring MVC 3.0

    Hi Friends,

    I am creating an application using Spring MVC 3.0 and trying to use session tracking in it.
    Not sure whats the best way to use HttpSession tracking in Spring MVC.

    To be specific, this is what I am trying to do:

    I have a controller, which has onSubmit() method overriden in it.
    It takes the input parameters as a java bean from a html screen, and processes it.
    Till this point, everything is ok, but I want to store the bean in session as well, for further use in the same session.
    Could somebody please guide me how do I do that?

    This is my Controller Code:

    public ModelAndView onSubmit(Object command)
    throws ServletException {

    NewPatientRegistration patient = ((NewPatientRegistration) command);
    logger.info("Patient info recieved:" + patient);
    long patientId = 0;
    try {
    patientId = newPatientManager.savePatient(patient);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    patient.setPatientId(patientId);
    Map<String, Object> myModel = new HashMap<String, Object>();
    myModel.put("patient", patient);
    // I want to save this patient in session, so that I can use it in the //next view and so forth in this session.
    return new ModelAndView("newPatientRegSuccessTile","model",my Model);

    }

    Please suggest what is the best way to achieve this.
    Thanks,
    Nitin.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Use [ code][/code ] tags when posting code.

    You don't want to store the patient, store the Id and retrieve the patient in the next page/controller... That way you don't have to rely on the session and don't have any replication/serialization etc. issues...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2009
    Posts
    21

    Default

    that is a good idea.
    I can just send the patientId to my next controller through the URL rewriting, and and fetch details there.

    But anyways, any idea/ or any link to an article which suggests a good way to use session tracking in Spring MVC, if I really need to use sessions at some place. (I know there is nothing Spring specific in tracking a normal HttpSession, but still wanted to know if there any best practice rule or something)

    Thanks a lot for your reply.

    Nitin.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Simply put it in the session. Spring only put simple types on the url, if you want anything else you need to do it yourself...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •