arm*_*ock 2 css url spring spring-mvc
我是 Spring MVC 的新手,我遇到了 CSS 问题。当 URL 以斜线结尾时 CSS 不起作用。
链接像这样
<link rel="stylesheet" href="themes/style.css">
mvc:resources mapping
<mvc:resources mapping="/themes/**" location="/WEB-INF/themes/"/>
和 requestMapping 像这样
@RequestMapping("/login")
public ModelAndView loginPage() {
ModelAndView model = new ModelAndView("login");
return model;
}
Run Code Online (Sandbox Code Playgroud)
所以问题是当我输入一个像../login
css 正常加载的 URL时,但是当我输入../login/
结尾斜杠时,css 不会加载。好吧,这里有很多类似的问题,但没有一个是针对 Spring MVC 的。
代替
<link rel="stylesheet" href="themes/style.css">
Run Code Online (Sandbox Code Playgroud)
尝试这个:
<link rel="stylesheet" href="/themes/style.css">
Run Code Online (Sandbox Code Playgroud)
当您将href="themes/style.css"
then 用于 url 时:.../login/
css 文件的请求 url 如下所示:
.../login/themes/style.css
Run Code Online (Sandbox Code Playgroud)
这是不正确的。当你使用href="/themes/style.css"
then 它总是应该导致:
.../themes/style.css
Run Code Online (Sandbox Code Playgroud)
更新:
如果是jsp页面,则<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
在页面顶部添加
并更改:
<link rel="stylesheet" href="themes/style.css">
Run Code Online (Sandbox Code Playgroud)
进入
<link rel="stylesheet" href="<c:url value="/themes/style.css" />">
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1861 次 |
最近记录: |