*.do表示后缀为do的才会拦截
<url-pattern>*.do</url-pattern>
/ 表示任何请求都要经过DispatcherServlet 包括图片、css 此时需要springmvc-servlet.xml内释放静态资源
静态资源可以正常的显示。
需要在springmvc的配置文件中添加。
springmvc-servlet.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd 7 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 8 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"> 9 <context:component-scan base-package="com.zhiyou100.wc.controllter"/> 10 11 <!-- 开启注解驱动 --> 12 <mvc:annotation-driven/> 13 <!-- 释放静态资源 --> 14 <mvc:default-servlet-handler/> 15 16 <!-- 视图解析器 --> 17 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 18 <property name="prefix" value="/WEB-INF/views/"/> 19 <property name="suffix" value=".jsp"/> 20 21 </bean> 22 23 24 25 </beans>
web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <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"> 3 <display-name>Springmvc-0903</display-name> 4 <welcome-file-list> 5 <welcome-file>index.html</welcome-file> 6 <welcome-file>index.htm</welcome-file> 7 <welcome-file>index.jsp</welcome-file> 8 <welcome-file>default.html</welcome-file> 9 <welcome-file>default.htm</welcome-file> 10 <welcome-file>default.jsp</welcome-file> 11 </welcome-file-list> 12 13 <!-- The front controller of this Spring Web application, responsible for handling all application requests --> 14 <servlet> 15 <servlet-name>springmvc</servlet-name> 16 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 17 <init-param> 18 <param-name>contextConfigLocation</param-name> 19 <!-- --> 20 <param-value>classpath:spring/springmvc-*.xml</param-value> 21 </init-param> 22 <load-on-startup>1</load-on-startup> 23 </servlet> 24 25 <!-- Map all requests to the DispatcherServlet for handling --> 26 <servlet-mapping> 27 <servlet-name>springmvc</servlet-name> 28 <!-- *.do表示后缀为do的才会拦截 --> 29 <!-- <url-pattern>*.do</url-pattern> --> 30 <!-- /表示任何请求都要经过DispatcherServlet 包括图片、css 此时需要springmvc-servlet.xml内释放静态资源 --> 31 <url-pattern>/</url-pattern> 32 </servlet-mapping> 33 </web-app>