java - 使用 jsp request.getContextPath() 使 eclipse 无法识别 css 文件

标签 java html css eclipse jsp

我正在做一个元素,我正在使用一个 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/

相关文章:

java - 使用PrintWriter和DataOutputStream在java中写入同一个文件

java - 将字符串 (Last\First\tAg) 转换为包含元素 {Last, First, Age} 的数组

java - Java 中来自静态上下文的模糊调用

php - 使用 php 生成脚本或使用 json

javascript - scrollTop() 返回元素下方的位置

html - 在CSS中获取浅色透明文本字段

java - XPathFactoryImpl 未找到错误(使用 myBatis)

html - 在神社上保留\n

javascript - JQuery 从 onclick 函数中检索数据属性

css - 你如何在前面获得 CSS 插入框阴影?