SpringMVC-DispatcherServlet工作流程及web.xml配置
工作流程:
web.xml
示例:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="3.0" 3 xmlns="http://java.sun.com/xml/ns/javaee" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 6 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 7 <display-name></display-name> 8 <welcome-file-list> 9 <welcome-file>/WEB-INF/views/home.jsp</welcome-file> 10 </welcome-file-list> 11 <!-- 加载指定位置的上下文配置文件 --> 12 <context-param> 13 <param-name>contextConfigLocation</param-name> 14 <param-value>classpath:applicationContext.xml</param-value> 15 </context-param> 16 <context-param> 17 <param-name>log4jConfigLocation</param-name> 18 <param-value>classpath:log4j.properties</param-value> 19 </context-param> 20 <!-- 定义LOG4J监听器 --> 21 <listener> 22 <listener-class> 23 org.springframework.web.util.Log4jConfigListener 24 </listener-class> 25 </listener> 26 <listener> 27 <listener-class> 28 org.springframework.web.context.ContextLoaderListener 29 </listener-class> 30 </listener> 31 <servlet> 32 <servlet-name>Spring</servlet-name> 33 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 34 <!-- 表示启动容器时初始化该servlet --> 35 <init-param> 36 <param-name>contextConfigLocation</param-name> 37 <param-value>classpath:Spring-servlet.xml</param-value> 38 </init-param> 39 <load-on-startup>1</load-on-startup> 40 </servlet> 41 <servlet-mapping> 42 <servlet-name>Spring</servlet-name> 43 <!-- 表示哪些请求需要交给Spring Web MVC处理,/是用来定义默认servlet映射的。也可以如“*.html”表示拦截所有以html为扩展名的请求 --> 44 <url-pattern>/</url-pattern> 45 </servlet-mapping> 46 <!-- 使用spring解决中文乱码 --> 47 <filter> 48 <filter-name>CharacterEncodingFilter</filter-name> 49 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 50 <init-param> 51 <param-name>encoding</param-name> 52 <param-value>utf-8</param-value> 53 </init-param> 54 </filter> 55 56 <filter-mapping> 57 <filter-name>CharacterEncodingFilter</filter-name> 58 <url-pattern>/*</url-pattern> 59 </filter-mapping> 60 </web-app>优质内容筛选与推荐>>