解决SpringMVC对js css等静态资源拦截

来源:互联网 发布:手机网页编辑软件 编辑:程序博客网 时间:2024/05/02 06:02

解决办法

在springMVC-servlet.xml配置文件中,配置mvc:resources

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:mvc="http://www.springframework.org/schema/mvc"       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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.xsd">    <mvc:annotation-driven />    <context:component-scan base-package="com.demo.web"/>      <mvc:resources location="/" mapping="/**/*.html"/>      <mvc:resources location="/" mapping="/**/*.js"/>      <mvc:resources location="/" mapping="/**/*.css"/>      <mvc:resources location="/" mapping="/**/*.png"/>      <mvc:resources location="/" mapping="/**/*.gif"/>  </beans>

tips: mapping对应的静态文件的路径为文件的绝对路径。

1 0