有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用jsp请求。getContextPath()使eclipse无法识别css文件

我正在做一个项目,我正在使用css文件。 起初我只是喜欢使用它在项目中的位置的绝对url,但浏览器没有这样看,所以我添加了一个jsp请求。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>


共 (2) 个答案

  1. # 1 楼答案

    对我来说,它正在工作,确保你的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>
    
  2. # 2 楼答案

    我找到了一个解决方案,只是用“.”代替了它 比如

    <link rel="stylesheet" type="text/css"
    href="./cerulean/default.css">