web mvc URL-service mapping

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

Spring web mvc URL mapping involves these stages.

web.xml: Declaration of DispatcherServlet bootstrap.

web.xml: Mapping the bootstrap to request URL pattern in web.xml.
The following maps any request URL with the pattern
http://{hostname}:{port}/{context}/v/{anything else}
to be handled by DispatcherServlet.

In mvc-context.xml:
  • Declaring InternalResourceViewResolver as a bean to be instantiated
  • Using the prefix parameter to instruct the bean where to find the resource
  • Using the suffix parameter to indicate to the bean the file suffix to expect
<bean id="viewResolver"
  <property name="prefix">
  <property name="suffix">

In DurianMVController:
  • Annotating DurianMVController class to indicate it as an MVC controller,
  • for DispatcherServlet thread to instantiate as a singleton.
public class DurianMVController

  • DispatcherServlet thread to discover request handlers in DurianMVController, where request handlers are annotated by @RequestMapping.
  • Map the request handler to its final URL declared in @RequestMapping.
  • Construct the select-options HTML-fragment from the util:map zipMap.
  • Pass the select-options HTML-fragment to Hello.jsp, as model attribute "zippers".
  • request handler method to return the name of the resource ("Hello") which will service the request
@RequestMapping(value = "/h1", method = RequestMethod.GET)
public String handleRequestJoyfully(ModelMap model) throws Exception {

    StringBuilder selectOpts = generateSelectOptions(zipMap);
    model.addAttribute("zippers", selectOpts.toString());

    return "Hello";

The URL to be used as mapping key is constructed as
  • http://{hostname}:{port}/{context} +
  • {web.xml servlet mapping = /v/} +
  • {class level @RequestMapping in mvc controller = none} +
  • {@RequestMapping in request handler in mvc controller = /h1 }
There is no @RequestMapping annotation at DurianMVController class declaration level. Presuming default and local deployment, the URL works out to be

The resource to be invoked to service this URL is constructed as
  • {mvc-context.xml:viewResolver prefix = /WEB-INF/views/} +
  • {String returned byhandleRequestJoyfully = Hello} +
  • {mvc-context.xml:viewResolver suffix = .jsp}

Therefore, the following resource needs to be created to service the request thro that URL

1 comment: