Session Handling in Spring MVC 3.0?

Have a look at my (non-perfect) use of session data.

Up vote 0 down vote favorite share g+ share fb share tw.

I am using session. SetAttribute to store user object after login. In next controller, I have @SessionAttribute for the same user and @ModelAttribute for same object to be used in the method mapped to a RequestMapping.

After login if I click any link in the user home page it give HttpSessionRequiredException: Session attribute '' required - not found in session I am not sure what I am doing wrong. I went through many article and question in this site as well but could find any solution. The user object which I am storing in session stores user's account details which are required in all the controller to get different information from DB.

I using SessionAttribute is wrong should I use HttpSession instead in all the controller and get the object from session manually or there is a proper way to handle in spring 3.0. Please note that this user object is not backing any form just login, but contains many other details. As help would be good.

Session spring-mvc link|improve this question edited Nov 28 '11 at 22:17skaffman114k8136227 asked Nov 28 '11 at 22:16Amit1047 62% accept rate.

Have a look at my (non-perfect) use of session data: @Controller @SessionAttributes("sharedData") public class RegistrationFormController { @Autowired private SharedData sharedData; // bean with scope="session" @RequestMapping(value = {"/registrationForm"}, method = RequestMethod. GET) public ModelAndView newForm() { final ModelAndView modelAndView = new ModelAndView("registrationForm"); modelAndView. AddObject("registrationForm", new RegistrationForm()); // I want to render some data from this object in JSP: modelAndView.

AddObject("sharedData", sharedData); return modelAndView; } @RequestMapping(value = {"/registrationForm"}, method = RequestMethod. POST) public String onRegistrationFormSubmitted(HttpServletRequest request, @ModelAttribute("registrationForm") RegistrationForm registrationForm, BindingResult result) { if (result.hasErrors()) { return "registrationForm"; } // Perform business logic, e.g. Persist registration data return "formSubmitted"; } }.

Hi dma_k I guess this will not be helpful in my case as I have user details to be stored in session. And in you example your storing sharedData which I cannot do as user details cannot be shared. – Amit Nov 29 '11 at 20:17 @Amit: How do you create your initial user details?

E.g. How does the factory method UserDetials createUserDetails(...) {} signature look like? – dma_k Nov 29 '11 at 23:19.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions