web.xml中配置:
<servlet>
<servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>分析原因:
因为mapping使用的是/ 默认拦截所有。
解决方案:
在spring-mvc的配置文件中添加:
<mvc:default-servlet-handler/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven /> <!-- 处理静态资源的请求 --> <mvc:resources location="/resources/" mapping="/resources/**" /> <mvc:resources mapping="/images/**" location="/images/" cache-period="31556926" /> <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926" /> <mvc:resources mapping="/css/**" location="/css/" cache-period="31556926" /> 提示:如果添加了 <mvc:default-servlet-handler/>提示错误信息
The prefix "mvc" for element "mvc:annotation-driven" is not bound.
解决方案:
在bean添加如下:
xmlns:mvc="http://www.springframework.org/schema/mvc"
在 xsi:schemaLocation中添加:
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd