SpringMVC访问静态资源

来源:互联网 发布:c语言入门txt免费下载 编辑:程序博客网 时间:2024/05/23 02:02

1.原因

因为springmvc的拦截是全部拦截,所以js会被拦截掉,返回404

2.解决

在Spring的配置文件中做如下配置:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:attr="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    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.xsd      http://www.springframework.org/schema/mvc      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"        >    <context:component-scan base-package="com.shen.test"></context:component-scan>    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/WEB-INF/views/"></property>        <property name="suffix" value=".jsp"></property>    </bean>    <!-- 访问静态资源必须的设置 -->    <mvc:default-servlet-handler/>    <mvc:annotation-driven></mvc:annotation-driven></beans>

注意

我开始的时候,也是这么设置的,但是把资源文件都放在了WEB-INF文件夹下了,所以不能访问到

应该把资源文件放到WEB-ROOT文件夹下

原创粉丝点击