The configuration of spring MVC in Web. xml

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.