Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring MVC: Possible to submit a form without dependency on HttpSession

 
Ted Hankey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it possible to submit a form in a JSP to a Spring Controller without the dependency on a HttpSession?

My Controller is defined as follows, with a load.do GET request and a save.do POST request:

@Controller
@RequestMapping("/optRules")
@SessionAttributes({"optRulesForm", "optDeskForm"})
public class OptRulesController {
.
.
.
@RequestMapping(value = "/load.do")
public ModelAndView getRuleAttributesAndRules(ModelMap model, HttpSession session, @RequestParam
String desk) {
session.setAttribute("desk", desk);

// Logic here to retrieve optRulesForm

model.addAttribute("optRulesForm", optRulesForm);

return new ModelAndView("opt/optRules", model);
}
.
.
.
@RequestMapping(value = "/save.do")
public ModelAndView saveRuleAttributesAndRules(@Valid
@ModelAttribute("optRulesForm")
OptRulesFormDTO optRulesForm, BindingResult bindingResult, HttpSession session, Principal principal, ModelMap model) {

// Logic here to save optRulesForm

model.addAttribute("optRulesForm", optRulesForm);

new ModelAndView("opt/optRules", model);
}
.
.
.

The problem is that I am adding new functionality to an existing application, and the session timeout interval is set to 10 minutes in the web.xml file.

This means that when I attempt to invoke save.do after 10 minutes that I get the following Exception:
HttpSessionRequiredException: Session attribute 'optRulesForm' required - not found in session

Annotating a method with @ModelAttribute will not work either, as I need the OptRulesFormDTO to be populated from the submitted form.

Therefore, I am wondering if it is possible to submit a form once the session has expired? I'd have thought there would be some way to achieve this.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, just don't use HttpSession. You can put things and get things from the Model, Request, Response anything you want.

@ModelAttribute
Pass in a Model object to your controller method and put stuff in it to get into the Response.

There are so many ways to do this without having to put anything in HttpSession.

But too many to post them all, so unfortunately, I have to direct you to the documentation

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-modelattrib

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic