Passing parameters to the mvc view


GitHub: https://github.com/SylkeWay/synthful

Following the previous page, with a local development server configured with the default port, the abstract URL
http://{hostname}:{port}/{context}/v/h1
would resolve as
http://localhost:8080/durian/v/h1
Which will be serviced by
/WEB-INF/views/Hello.jsp
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">
</form>
The form has the action "duriangrove/h2g2j".
Submitting of the form would invoke the URL
http://localhost:8080/durian/v/duriangrove/h2g2j
DurianGroveMVController
There is another mvc controller DurianGroveMVController with the mapping "/duriangrove",
@Controller
@RequestMapping("/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 ? addr.city : "Walla Walla";
    String state = addr!=null ? addr.state.name() : "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);

    logger.info("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
http://localhost:8080/durian/v/duriangrove/h2g2j

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
/WEB-INF/views/Cello.jsp

No comments:

Post a Comment