Spring MVC: Session attribute required - not found in session?

As the Javadoc on @SessionAttribute indicates use of the annotation means you want store the specified model attributes in the session, which means you need to add them to the model first. Spring MVC will not create them.

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

I am receiving the following error on submitting my form: org.springframework.web. HttpSessionRequiredException: Session attribute 'rulesForm' required - not found in session at org.springframework.web.servlet.mvc.annotation. AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.

RaiseSessionRequiredException(AnnotationMethodHandlerAdapter. Java:722) My JSP contains the following: ... My Controller contains the following: @Controller @RequestMapping("/rules") @SessionAttributes({"rulesForm", "deskForm"}) public class RulesController { . .

. @RequestMapping(value = "/save. Do") public ModelAndView saveRuleAttributesAndRules(@Valid @ModelAttribute("rulesForm") RulesFormDTO rulesForm, BindingResult bindingResult, HttpSession session, Principal principal) { It seems that if I leave my browser open for a while with my form displaying and then I attempt to perform a submit after some time I get this error.

Really what I want to happen in this case is for the new "rulesForm" object to be created...how can I achieve this? Thanks spring-mvc link|improve this question asked Jan 20 at 20:42David Joyce18818 76% accept rate.

As the Javadoc on @SessionAttribute indicates use of the annotation means you want store the specified model attributes in the session, which means you need to add them to the model first. Spring MVC will not create them. In other words when you add a @ModelAttribute("rulesForm") controller method argument you're telling Spring MVC to look for it in the model or create a new instance if not found.

However if you also add @SessionAttributes, Spring MVC will not attempt to create a new instance and will expect the object to be either in the model or in the session. You can use a @ModelAttribute method to add your object initially.

Adding a @ModelAttribute method is not what I want either. I want the data that is posted in the form to be mapped to the RulesForm object. How come when my form is submitted it is not performing the binding?

– David Joyce Jan 26 at 18:26.

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