把web.xml和springmvc放在同一目录下,把spring.xml放在resource目录下
1、web.xml
主要是配置web项目启动时加载的信息,
比如<context-param/>配置参数,
<listener/>配置你的监听器,
<filter/>配置过滤器,
<servlet/>配置你的servlet实现。
web.xml里面有spring.xml、springmvc.xml的引用。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns: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">
<display-name>Archetype Created Web Application</display-name>
//这里配置的编码过滤器
<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>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
//将spring.xml引入进行,取得名字叫applicationContext.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
//将springmvc引入进来,取的是默认的名字dispatcher-servlet.xml
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>or