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.
<servlet>
  <servlet-name>mvc-dispatcher</servlet-name>
  <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:/springweb/**-context.xml
    </param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

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.
<servlet-mapping>
  <servlet-name>mvc-dispatcher</servlet-name>
  <url-pattern>/v/*</url-pattern>
</servlet-mapping>

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"
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix">
    <value>/WEB-INF/views/</value>
  </property>
  <property name="suffix">
    <value>.jsp</value>
  </property>
</bean>

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

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());

    logger.info("handleRequestJoyfully");
    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
http://localhost:8080/durian/v/h1

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

8 comments:

  1. The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. machine learning projects for final year In case you will succeed, you have to begin building machine learning projects in the near future.

    Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.

    Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.

    The Nodejs Projects Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete