<?xml version="1.0" encoding="UTF-8">
<!-- web.xml 主要作用:
1、装载DispatcherServlet类;
2、读取Spring配置文件;
3、设置初始化参数;
4、加入标记库;
4、路由设置;
-->
<!-- web-app中要有各种命名空间-->
<web-app version="2.4" xmlns=""
xmlns=""
xsi:schemaLocation="">
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--contextConfigLocation用来指定Spring 配置文档的位置,可以指定多个配置文档,但要以逗号分隔
Spirng 默认为servlet名+“servlet.xml”,并放在WEB-INF目录下;如果不指定 contextConfigLocation,则默认 是防在WEB-INF目录下的dispatcherServlet-servlet.xml
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcherServlet-servlet.xml</param-value>
<!--如果servlet文件的命名方式是 上面的 servlet-name+"-servlet.xml",则可以不用这个初始化参数-->
</init-param>
<load-on-startup>1</load-on-startup>
<!--指定当Web启动时,加载servlet的顺序;当值>=0时,先加载小的,在加载大的;如果<0或者没有设定,将在web首次访问是加载;-->
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<!--指定访问Servlet是URL相对路径-->
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
<!--end-->
<!-----------------------------------------Example---------------------------------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Web MVC Hello World Application</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>