The moose likes Spring and the fly likes Spring MVC: Possible to submit a form without dependency on HttpSession Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "Spring MVC: Possible to submit a form without dependency on HttpSession" Watch "Spring MVC: Possible to submit a form without dependency on HttpSession" New topic
Author

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

Ted Hankey
Greenhorn

Joined: Jun 20, 2010
Posts: 2
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

Joined: Feb 05, 2001
Posts: 16624

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
IntelliJ Java IDE
 
subject: Spring MVC: Possible to submit a form without dependency on HttpSession
 
Threads others viewed
@Responsebody for HTTP msg and a View to show the HTTP response msg
MVC form action problem
org.springframework.web.HttpSessionRequiredException: Session attribute 'user' required - not found
@ModelAttribute behavior
New value is inserted into db in @ManyToOne relation instead of update
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture