Spring MVC Framework
The Spring Web MVC structure gives Model-View-Controller (MVC) engineering and prepared parts that can be utilized to create adaptable and inexactly coupled web applications. The MVC design brings about isolating the distinctive parts of the application (input rationale, business rationale, and UI rationale), while giving a free coupling between these elements.
The Model typifies the application information and all in all they will comprise of POJO.
The View is in charge of rendering the model information and as a rule it creates HTML yield that the customer's program can interpret.
The Controller is in charge of preparing client demands and building a fitting model and passes it to the view for rendering.
The Spring Web display see controller (MVC) system is structured around a DispatcherServlet that handles all the HTTP solicitations and reactions. The ask for preparing work process of the Spring Web MVC DispatcherServlet is shown in the accompanying graph −
Following is the succession of occasions comparing to an approaching HTTP ask for to DispatcherServlet −
After getting a HTTP ask for, DispatcherServlet counsels the HandlerMapping to call the fitting Controller.
The Controller takes the demand and calls the fitting administration techniques dependent on utilized GET or POST strategy. The administration strategy will set model information dependent on characterized business rationale and returns see name to the DispatcherServlet.
The DispatcherServlet will take assistance from ViewResolver to pickup the characterized view for the request.
Once see is concluded, The DispatcherServlet passes the model information to the view which is at long last rendered on the browser.
All the previously mentioned parts, for example HandlerMapping, Controller, and ViewResolver are portions of WebApplicationContext w which is an augmentation of the plainApplicationContext with some additional highlights important for web applications.
You need to outline that you need the DispatcherServlet to deal with, by utilizing a URL mapping in the web.xml document. Coming up next is a guide to indicate announcement and mapping for HelloWeb DispatcherServlet model −
<web-app id = "WebApp_ID" version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Spring MVC Application</show name> <servlet> <servlet-name>HelloWeb</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>HelloWeb</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping> </web-app>
The web.xml document will be kept in the WebContent/WEB-INF index of your web application. Endless supply of HelloWeb DispatcherServlet, the system will attempt to stack the application setting from a document named [servlet-name]-servlet.xml situated in the application's WebContent/WEB-INFdirectory. For this situation, our document will be HelloWebservlet.xml.
Next, <servlet-mapping> tag demonstrates what URLs will be dealt with by which DispatcherServlet. Here all the HTTP asks for completion with .jsp will be taken care of by the HelloWeb DispatcherServlet.
If you would prefer not to run with default filename as [servlet-name]-servlet.xml and default area as WebContent/WEB-INF, you can redo this document name and area by including the servlet audience ContextLoaderListener in your web.xml record as pursues −