springmvc在web.xml中的常用配置

来源:互联网 发布:java 中编译后无src 编辑:程序博客网 时间:2024/04/29 05:16
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">  <display-name>Demo</display-name>  <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list>  <context-param>  <description>springmvc配置文件</description>  <param-name>contextConfigLocation</param-name>  <param-value>classpath:com/resource/spring_*.xml</param-value>  </context-param>    <servlet>  <description>spring核心分发器</description>  <servlet-name>springDispatcher</servlet-name>  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  <init-param>  <param-name>contextConfigLocation</param-name>  <param-value>classpath:com/resource/spring_*.xml</param-value>  </init-param>  <load-on-startup>1</load-on-startup>  </servlet>  <servlet-mapping>  <servlet-name>springDispatcher</servlet-name>  <url-pattern>*.mvc</url-pattern>  </servlet-mapping>    <listener>  <description>spring上下文侦听器</description>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>    <filter>  <description>spring编码过滤器</description>  <filter-name>spring-characterEncoding-filter</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>  </filter>  <filter-mapping>  <filter-name>spring-characterEncoding-filter</filter-name>  <url-pattern>/*</url-pattern>  </filter-mapping>
<servlet-mapping>静态资源处理<servlet-name>default</servlet-name><url-pattern>/*.html</url-pattern><url-pattern>/*.jpg</url-pattern><url-pattern>/*.js</url-pattern><url-pattern>/*.css</url-pattern></servlet-mapping></web-app>

有关springmvc的静态资源处理http://blog.csdn.net/shewmi/article/details/78015070

有关路径统配问题http://blog.csdn.net/shewmi/article/details/77998293


spring4.3.8

需要注意的事项:

1、配置文件资源路径建议使用下划线_的形式,如spring_mvc,不推荐使用spring-mvc,因为springmvc默认会查找dispatherServlet-servlet.xml文件,如果找不到,则会匹配*-servlet.xml的配置文件,所以使用-容易造成配置文件不存在的错误。

2、上下文侦听器需springmvc配置文件,因此需要先配置springmvc配置文件路径参数。

3、编码过滤器在使用spring表单的时候非常有用。

原创粉丝点击