-
Dec 14th, 2010, 05:11 PM
#1
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.
-
Dec 15th, 2010, 01:07 AM
#2
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...
-
Dec 15th, 2010, 10:05 AM
#3
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.
-
Dec 16th, 2010, 02:23 AM
#4
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules