0

我有一个文件 FixHome.jsp,它试图显示来自 style.css 的徽标和格式。但是,当我运行 .jsp 文件时,图像不会出现,并且 stye.css 文件的格式也没有实现。

文件位置位于 FixConnections 项目下,如下所示:

/WebContent/FixHome.jsp

/WebContent/Resources/style.css

/WebContent/Resources/needhamlogo2.bmp

我正在使用 Eclipse 并运行 Tomcat 7.0

<html>
<head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/Resources/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Fix Connections</title>
</head>
<body>
<table bgcolor="black" id="shell" height="100%" width="100%">
 <tr height="30">
  <td bgcolor="white">
     <img src="${pageContext.request.contextPath}/Resources/NeedhamLogo2.bmp"/> 
  </td>
  <td bgcolor="white"> 
    FIX Connections 
  </td> 
</tr> 
</body>
</html>

如果我正确引用了图像和 .css 文件,请告诉我。

4

2 回答 2

1

只需使用相对href:

href="Resources/style.css"

或者,添加一个前导斜杠。contextPath 只返回一个字符串,因此您的 href 呈现如下内容:

href="ctxt/Resources/style.css"

虽然您需要以下之一:

href="/ctxt/Resources/style.css"
href="Resources/style.css"
于 2013-10-20T20:25:28.337 回答
0

尝试使用默认 servlet 参见文档 http://tomcat.apache.org/tomcat-6.0-doc/default-servlet.html

在jsp中(示例)

    <link href="css/custom.css" rel="stylesheet" type="text/css" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />

在 web.xml(示例)中

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>
于 2013-10-21T04:48:01.310 回答