SSM Learning-4. Configuring Web. Xml

Source: Internet
Author: User

In the Web. XML Main configuration:

1. Start the spring container

2.SPRINGMVC Interceptor

3. Character encoding Filter

4.REST-style URI

The specific configuration is as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns= "Http://java.sun.com/xml/ns/javaee"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
ID= "webapp_id"version= "2.5"> <!--start the spring container - <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:applicationContext.xml</Param-value> </Context-param> <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <!--Springmvc's front-end controller intercepts all requests - <servlet> <Servlet-name>Dispatcherservlet</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Dispatcherservlet</Servlet-name> <Url-pattern>/</Url-pattern> </servlet-mapping> <!--Character encoding Filters - <Filter> <Filter-name>Characterencodingfilter</Filter-name> <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class> <Init-param> <Param-name>Encoding</Param-name> <Param-value>Utf-8</Param-value> </Init-param> <Init-param> <Param-name>Forcerequestencoding</Param-name> <Param-value>True</Param-value> </Init-param> <Init-param> <Param-name>Forceresponseencoding</Param-name> <Param-value>True</Param-value> </Init-param> </Filter> <filter-mapping> <Filter-name>Characterencodingfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping> <!--convert a page's normal POST request to a put or delete request using a restful URI - <Filter> <Filter-name>Hiddenhttpmethodfilter</Filter-name> <Filter-class>Org.springframework.web.filter.HiddenHttpMethodFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Hiddenhttpmethodfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping></Web-app>

The dispatcherservlet-servlet.xml configuration is as follows:

<?XML version= "1.0" encoding= "UTF-8"?>  <Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3. 1.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/conte Xt/spring-context-3.1.xsd Http://www.springframework.org/schema/mvc HTTP://WWW.SPRINGFRAMEWORK.O Rg/schema/mvc/spring-mvc-3.1.xsd ">      <!--SPRINGMVC Configuration -    <!--Scan Configuration -    <Context:component-scanBase-package= "Com.atguigu"use-default-filters= "false" >        <Context:include-filtertype= "Annotation"expression= "Org.springframework.stereotype.Controller"/>    </Context:component-scan>    <!--View Parser Configuration -    <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver">        < Propertyname= "prefix"value= "/web-inf/views/"></ Property>        < Propertyname= "suffix"value= ". jsp"></ Property>    </Bean>    <!--Two standard configurations -    <!--give Tomcat a request that SPRINGMVC cannot process -    <Mvc:default-servlet-handler/>    <!--can support SPRINGMVC more advanced functions, JSR303 check ajax, etc. -    <Mvc:annotation-driven/></Beans>

SSM Learning-4. Configuring 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.