
@RequestMapping(value="/pages/contactus.html") private ModelMap executeContactUs() { return somestuff; }

DispatcherServlet Handling Incoming Web Request
- Mapping all the controllers provided which are annotated
- Creating beans for all the classes which are annotated
- Also configuring the dependencies between the classes and controllers.
- Migration from traditional JSP to JSPs consisting of Spring tags: In order to do this well, it would be good to learn concepts around spring mvc tags and their attributes. First and foremost, for all the spring tags to work, tag libraries need to be imported. Following are some key to-do things:
- The value to the path attribute of <form:input> tag should be same as POJO property.
- modelAttribute of spring form tag plays a vital role in passing objects from views to controllers and vice versa.
- Migration from traditional Controller to Spring-MVC based Controller: Following are listed some important details in this regard:
- The major changes be done while converting traditional controller to Spring controllers revolve basically around the annotations and mapping the requests to the corresponding methods in the controller.
- RequestMapping is used to map URL requests that come from the browser to the corresponding methods. The method attribute of RequestMapping annotation provides the information regarding the type of the request whether it is GET method or POST method.
- Every controller should be annotated with @Controller.
- In order to instantiate and inject objects, it is suggested to use @autowired annotation. This annotation helps to auto-wire the object.
- Configuration of Web.xml to initialize Spring Container (Application Context): This is the final step in which a mapping needs to be provided for the dispatcher servlet. The dispatcher servlet is represented using an XML file (responsible for handling beans and dependencies) and whose mapping needs to be mentioned in web.xml. Following represents the configuration in web.xml file:
Above configuration represents that all requests ending with
.form
will be handled by theexample
DispatcherServlet.
Once you are done with above, as a final step, create the war file and deploy it into tomcat and test the application. That is it!
- Population & Samples in Statistics: Examples - January 9, 2023
- One-way ANOVA test: Concepts, Formula & Examples - January 8, 2023
- Linear Regression Explained with Real Life Example - January 8, 2023
Leave a Reply