Passing parameters to the mvc view


Following the previous page, with a local development server configured with the default port, the abstract URL
would resolve as
Which will be serviced by
Hello.jsp has a HTML form. Stripping away the TABLE enclosure, these are the essential elements of the form.
<form method="post" action="duriangrove/h2g2j" name="h2g2form">
<input readonly="readonly" name="who" value="Annie Walker">
<input name="what" value="MIA agent">
<input name="when" value="12/12/1212 12:12:12">
<input value="Post it" name="postit" type="submit">
The form has the action "duriangrove/h2g2j".
Submitting of the form would invoke the URL
There is another mvc controller DurianGroveMVController with the mapping "/duriangrove",
public class DurianGroveMVController
The controller has a request handler "anotherHandleRequest" with the mapping "/h2g2j"
@RequestMapping(value = "/h2g2j", method = {RequestMethod.GET,RequestMethod.POST})
public String anotherHandleRequest(ModelMap model,
        @RequestParam("who") String who,
        @RequestParam("street") String street,
        @RequestParam("zip") int zip)            
throws Exception {
    Address addr = zipMap.get(zip);
    String city = addr!=null ? : "Walla Walla";
    String state = addr!=null ? : "ZZ";
    String where = String.format("%s, %s, %s %05d", street, city, state, zip);
    model.addAttribute("who", who);
    model.addAttribute("where", where );
    model.addAttribute("what", season);"anotherHandleRequest: {},{},{} ", who, where, season);
    return "Cello";
Following the scene laid out in the previous page
  • http://{hostname}:{port}/{context} +
  • {web.xml servlet mapping = /v/} +
  • {class level @RequestMapping in mvc controller = duriangrove} +
  • {@RequestMapping in request handler in mvc controller = /h2g2j }

Which matches the URL

Following the details of the previous page again, the path of the resource is constructed as
  • {mvc-context.xml:viewResolver prefix = /WEB-INF/views/} +
  • {String returned byhandleRequestJoyfully = Cello} +
  • {mvc-context.xml:viewResolver suffix = .jsp}

which resolves to

No comments:

Post a Comment