Creating a Spring MVC application

Spring MVC can be used for creating web applications. It provides an easy framework to map incoming web requests to a handler class (Controller) and create dynamic HTML output. It is an implementation of the MVC pattern. The Controller and Models are created as POJOs, and Views can be created using JSP, JSTL, XSLT, and even JSF. However, in this chapter, we will focus on creating Views using JSP and JSTL.

A web request is handled by four layers in Spring MVC:

  • Front controller: This is a Spring servlet configured in web.xml. Based on the request URL pattern, it passes requests to the Controller.
  • Controller: These are POJOs annotated with @Controller. For each Controller that you write, you need to specify a URL pattern that the Controller is expected to handle. Sub-URL patterns can be specified at the method level too. We will see examples of this later. Controller has access to Model and to HTTP request and response objects. Controller can delegate processing of a request to other business handler objects, get results, and populate the Model object, which is made available to View by Spring MVC.
  • Model: These are data objects. The Controller and View layers can set and get data from Model objects.
  • View: These are typically JSPs, but Spring MVC supports other types of Views too. See View technologies in the Spring documentation at https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-view.

We will learn Spring MVC in this chapter through examples, as we have been learning in some other chapters in this book. We will create a part of the same Course Management application using Spring MVC. The application will display a list of courses with options to add, remove, and modify them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.77.63