请帮我解决以下问题!我有配置:
<mvc:resources location="/images/" mapping="/images/**"/>
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/javascript/" mapping="/javascript/**"/>
并且所有内容都适用于我的资源,例如:
http://127.0.0.1:8080/baraholka/viewAdverts.brh
但是当我有这样的要求时:
http://127.0.0.1:8080/baraholka/viewTagAdverts/tag/2/1
其中:
@RequestMapping(value="/ajaxViewAdverts/tag/{id}/{currentPage}", method=RequestMethod.GET)
public ResponseEntity<byte[]> viewTagAdverts(@PathVariable("id") Integer id, @PathVariable(value="currentPage") Integer currentPage, ModelMap map, HttpServletRequest request, HttpServletResponse response){
byte view[] = {};
HttpHeaders httpHeaders = new HttpHeaders();
我明白了:
20:48:08.109 WARN [http-8080-4] org.springframework.web.servlet.DispatcherServlet:947 - No mapping found for HTTP request with URI [/baraholka/viewTagAdverts/tag/2/javascript/jquery.cookies.2.2.0.js] in DispatcherServlet with name 'baraholka'
20:48:08.109 WARN [http-8080-3] org.springframework.web.servlet.DispatcherServlet:947 - No mapping found for HTTP request with URI [/baraholka/viewTagAdverts/tag/2/javascript/baraholka.js] in DispatcherServlet with name 'baraholka'
20:48:08.140 WARN [http-8080-1] org.springframework.web.servlet.DispatcherServlet:947 - No mapping found for HTTP request with URI [/baraholka/viewTagAdverts/tag/2/javascript/jquery.lightbox-0.5.min.js] in DispatcherServlet with name 'baraholka'
20:48:08.156 WARN [http-8080-5] org.springframework.web.servlet.DispatcherServlet:947 - No mapping found for HTTP request with URI [/baraholka/viewTagAdverts/tag/2/javascript/jquery.ui.stars.js] in DispatcherServlet with name 'baraholka'
20:48:08.156 WARN [http-8080-2] org.springframework.web.servlet.DispatcherServlet:947 - No mapping found for HTTP request with URI [/baraholka/viewTagAdverts/tag/2/css/jqcloud.css] in DispatcherServlet with name 'baraholka'
20:48:08.171 WARN [http-8080-3] org.springframework.web.servlet.DispatcherServlet:947 - No mapping found for HTTP request with URI [/baraholka/viewTagAdverts/tag/2/images/login.png] in DispatcherServlet with name 'baraholka'
20:48:08.171 WARN [http-8080-1] org.springframework.web.servlet.DispatcherServlet:947 - No mapping found for HTTP request with URI [/baraholka/viewTagAdverts/tag/2/images/logo.png] in DispatcherServlet with name 'baraholka'
如何设置正确的映射?我也尝试过像 / images / 这样的映射,但它不起作用。
答案 0 :(得分:1)
您也可以像这样添加资源:
<base href="http://localhost:8080/" />
<link rel="icon" href="resources/images/favicon.ico" type="ico">
这不是一个好的解决方案,但我无法通过另一种方式解决我的应用程序中的类似问题
答案 1 :(得分:0)
我看起来你使用相对路径来引用模板中的静态资源,因此浏览器会将它们视为相对于当前页面,正如您在日志中看到的那样。
您需要使用<c:url>
构建完整路径,如下所示:
<script src = "<c:url value = "/javascript/baraholka.js" />"></script>