File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
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: 17260
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC: Possible to submit a form without dependency on HttpSession