问题描述
前台页面需要访问静态页面,在没有配置<mvc:resourcesmapping="/css/**"location="/css/"/><mvc:resourcesmapping="/js/**"location="/js/"/>时,进行debug,程序启动后,前台还是能够访问的,虽然样式加载不出来,但是确实是可以访问的。但是当我为了要访问静态资源,所以加上上面的配置后,程序启动后,前台访问,反而报错404,试了好久,始终不得行实在不知道是为什么~求解答,非常感谢了springmvc的配置文件:<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:util="http://www.springframework.org/schema/util"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"default-autowire="byName"><!--扫描controller(controller层注入)--><context:component-scanbase-package="com.demo.mvc.controller"/><mvc:resourcesmapping="/css/**"location="/css/"/><mvc:resourcesmapping="/js/**"location="/js/"/><!--避免IE在ajax请求时,返回json出现下载--><beanid="jacksonMessageConverter"class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"><propertyname="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value></list></property></bean><!--对模型视图添加前后缀--><!--<beanid="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"p:prefix="/WEB-INF/jsp/"p:suffix=".jsp"/>--><beanid="velocityViewResolver"class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"><propertyname="prefix"value="/"/><propertyname="contentType"><value>text/html;charset=UTF-8</value></property><propertyname="suffix"value=".vm"/></bean><beanid="velocityConfigurer"class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"><propertyname="resourceLoaderPath"value="/WEB-INF/vm/"/><propertyname="configLocation"value="classpath:velocity.properties"/></bean></beans>
web.xml配置:<!DOCTYPEweb-appPUBLIC"-//SunMicrosystems,Inc.//DTDWebApplication2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd"><web-app><display-name>ArchetypeCreatedWebApplication</display-name><!--读取spring配置文件--><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:conf/spring.xml;</param-value></context-param><!--Spring字符集过滤器--><filter><filter-name>SpringEncodingFilter</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>SpringEncodingFilter</filter-name><url-pattern>/</url-pattern></filter-mapping><listener><listener-class>org.springframework.web.util.Log4jConfigListener</listener-class></listener><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!--springMVC核心配置--><servlet><servlet-name>spring</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:conf/spring-mvc.xml</param-value></init-param><load-on-startup>2</load-on-startup></servlet><servlet-mapping><servlet-name>spring</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>
工程目录:
解决方案
解决方案二:
在<mvc:resources...前面加上<mvc:default-servlet-handler/>