我正在做一个元素,我正在使用一个 CSS 文件。 起初我只是喜欢使用它在元素中的位置的绝对 url 但浏览器没有那样看所以我添加了一个 jsp request.getContextPath() 方法并修复了它但现在 eclipse 的预览窗口没有看见。有什么建议吗?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath() %>/cerulean/default.css">
<title>Insert title here</title>
</head>
最佳答案
对我来说它正在工作,确保你的 href 路径是正确的。
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page session="false"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/resources/css/main.css">
</head>
<body>
<h2>home page!</h2>
<c:url var="helloWorldUrl"
value="helloWorld?message=hello world spring sample" />
<a href="${helloWorldUrl}">Say hello world to spring mvc</a>
</body>
</html>
关于java - 使用 jsp request.getContextPath() 使 eclipse 无法识别 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21502292/