Spring MVC passes all requests through a servlet controller-dispatcherservlet, and the servlet's job is to distribute request requests from a client to different SPRINGMVC controllers. Since it is a controller servlet, it needs to be configured in Web. Xml.
<servlet> <Servlet-name>Springmvc</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Springmvc</Servlet-name> <Url-pattern>/</Url-pattern> </servlet-mapping>
Once configured, all requests will be intercepted, depending on the configuration above, Dispatchservlet will load Springmvc-servlet.xml, in Springmvc-servlet.xml, we need to configure which view the SPRINGMVC controller uses by default, and declare a view parser bean:
<Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView"/> < Propertyname= "prefix"value= "/web-inf/views/"/> < Propertyname= "suffix"value= ". jsp"/> </Bean>
In order to successfully use the callout code in your code, you need to specify the annotation feature in this XML to open
</>
Specify the package where the controller resides
<base-package= "Com.springmvc.controller"/>
In addition to the label declaration, the Springmvc-servlet.xml form is:
<?XML version= "1.0" encoding= "UTF-8"?><BeansXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://www.springframework.org/schema/beans"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http:/ /www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd/HTTP Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd "> <Mvc:annotation-driven/> <Context:component-scanBase-package= "Com.springmvc.controller"/> <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView"/> < Propertyname= "prefix"value= "/web-inf/views/"/> < Propertyname= "suffix"value= ". jsp"/> </Bean></Beans>
The configuration of spring MVC in Web. xml