小弟最近刚学Spring mvc,遇到了不少问题。我配置了好了拦截问题但是仍然不能访问css、jpg等文件不知道是哪里配置错了,请各位前辈指教: web.xml如下 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>ShoppingMall2</display-name> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/resources/css/*</url-pattern> <url-pattern>/resources/img/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>mydispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:Spring/mydispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mydispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> 我的dispatcher.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "> <context:component-scan base-package="cn.zjs.shoppingmall" /> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"/> <mvc:default-servlet-handler/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans> 我的资源文件都放在WEB-INF下的resources下的css和img文件夹下面 |
|
20分
#1 |
因为你的配置拦截了所有的请求
在web.xml添加 <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css</url-pattern> </servlet-mapping> 试试这样可以不 |
#2 |
回复1楼: 这个我试过了,不是这里的问题。不过还是谢谢你啦 |
#3 |
去java吧问了下,问题出在路径,需要把resources文件夹从WEB-INF下面拿出来,再改变一下参数就可以取到了。
不知道是否可以放在resources文件夹下面。 |