在spring mvc中使用多个"mvc:resources"标签

Ash*_*ain 3 spring-mvc

我正在尝试使用spring v3.0.4中引入的新mvc标记库来提供静态资源.

我的spring配置看起来像这样

   <mvc:resources mapping="/scripts/**" location="/scripts/" />
   <mvc:resources mapping="/styles/**" location="/styles/" />
   <mvc:resources mapping="/images/**" location="/images/" />
Run Code Online (Sandbox Code Playgroud)

但它正在向DispatcherController发送/ styles/**的请求.我得到这个日志的空白页面.

2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <DispatcherServlet with name 'template' processing GET r
equest for [/template/styles/admin/struts-menu/menuExpandable.css]>

2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - <Matching patterns for request [/styles/ad
min/struts-menu/menuExpandable.css] are [/styles/**]>

2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - <URI Template variables for request [/styl
es/admin/struts-menu/menuExpandable.css] are {}>
2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - <Mapping [/styles/admin/struts-menu/menuEx
pandable.css] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@1ce0390] and 3 inte
rceptors>
2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Last-Modified value for [/template/styles/admin/struts-
menu/menuExpandable.css] is: -1>
2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.resource.ResourceHttpRequestHandler] - <Trying relative path [admin/struts-me
nu/menuExpandable.css] against base location: ServletContext resource [/styles/]>

2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.resource.ResourceHttpRequestHandler] - <Found matching resource: ServletConte
xt resource [/styles/admin/struts-menu/menuExpandable.css]>

2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.resource.ResourceHttpRequestHandler] - <Determined media type [text/css] for
ServletContext resource [/styles/admin/struts-menu/menuExpandable.css]>
2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.resource.ResourceHttpRequestHandler] - <Resource not modified - returning 304
>

2011-03-05 21:05:11,923 DEBUG [com......template.web.admin.interceptors.SideMenuAdminInterceptorV2] - <Entering postHandle()>
2011-03-05 21:05:11,923 INFO [com.....template.web.admin.interceptors.SideMenuAdminInterceptorV2] - <ServletPath : /styles/admin/str
uts-menu/menuExpandable.css, ContextPath : /template, PathTranslated : null>
2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Null ModelAndView returned to DispatcherServlet with na
me 'template': assuming HandlerAdapter completed request handling>
2011-03-05 21:05:11,923 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Successfully completed request>
Run Code Online (Sandbox Code Playgroud)

agp*_*gpt 8

我知道这是一个非常古老的问题,但是今天我遇到了同样的情况,后来为我工作..(希望它对某人有帮助)

1.)我在下面添加了以下内容:

<mvc:resources location="/css/" mapping="css/**"/>
<mvc:resources location="/js/" mapping="js/**"/>
<mvc:resources location="/images/" mapping="images/**"/>
Run Code Online (Sandbox Code Playgroud)

就在下面 <mvc:annotation-driven />

2.)我将样式表和js文件链接起来(即与/ css /或/ js /不同)

<link href="css/styleIndex.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
Run Code Online (Sandbox Code Playgroud)