gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:48:13 24 4
gpt4 key购买 nike

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

我的 spring 配置如下所示

   <mvc:resources mapping="/scripts/**" location="/scripts/" />
<mvc:resources mapping="/styles/**" location="/styles/" />
<mvc:resources mapping="/images/**" location="/images/" />

但是它正在向 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>

最佳答案

我知道这是一个非常古老的问题,但今天我遇到了同样的情况,并且以下内容对我有用..(希望它会对某人有所帮助)

1.) 我添加了以下几行:

<mvc:resources location="/css/" mapping="css/**"/>
<mvc:resources location="/js/" mapping="js/**"/>
<mvc:resources location="/images/" mapping="images/**"/>

就在<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>

关于spring-mvc - spring mvc中多个 "mvc:resources"标签的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5208273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com