0

I have a controller that a form posts to:

 @RequestMapping(value = "/formtest", method = RequestMethod.POST)
    public ModelAndView HandleFormPost()
    {
        ModelAndView mv = new ModelAndView("posttest");



        return mv;
    }

What are my options in retrieving the data from the form?

In asp.net I would just do:

Request.Form["key"] or Request["key"]

or I could use a parameter in my action FormCollection and then just do:

form["key"]

I am using spring MVC (version 3), what are my options?

1 Answer 1

2

You could do any of the following:

public ModelAndView handleFormPost(WebRequest request) {
   request.getParameter("key");
}

or

public ModelAndView handleFormPost(@RequestParam String key) {

}

There are many other options, but these two are the easiest.

A @RequestMapping-annotated method can take a wide variety of different arguments (you just add them to the method and Spring will supply them), and can return a wide variety of different return types. The options are listed here.

3
  • thanks! so a requestparam is either querystring or form value?
    – Blankman
    Feb 12, 2010 at 17:43
  • you're still thinking in ASP :)
    – skaffman
    Feb 12, 2010 at 18:06
  • was that an answer? now i'm confused hehe. I need a Response.End and also!
    – Blankman
    Feb 14, 2010 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.