【发布时间】:2014-05-15 19:22:48
【问题描述】:
我的项目结构:
你好.jsp:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Title</title>
<meta charset="utf-8">
<link href="<c:url value="/resources/myStyle.css" />" rel="stylesheet">
</head>
<body>
<h1>Text</h1>
<p>Text.</p>
</body>
</html>
myStyle.css:
body {
font-family: Arial, Verdana, sans-serif;
font-size: 11pt;
background-color: #f0f0f0;
color: #333;
}
h1 {
color: #a52a2a;
font-size: 24pt;
font-family: Georgia, Times, serif;
font-weight: normal;
}
p {
text-align: justify;
margin-left: 60px;
margin-right: 10px;
border-left: 1px solid #999;
border-bottom: 1px solid #999;
padding-left: 10px;
padding-bottom: 10px;
}
有人可以解释一下为什么 css 不起作用吗? 我使用 Intellij IDEA 作为 IDE 和 Tomcat。
这可行:
<style>
<%@include file="/resources/myStyle.css" %>
</style>
【问题讨论】:
-
在浏览器中查看源代码,查看您实际打印到
link href中的内容,并确定这是否是您 url 的正确相对路径。 -
将您的 mvc-dispatcher-servlet.xml 发布到您定义资源映射的位置。
-
问题出在 mvc-dispatcher-servlet 中。我需要添加这个: