如何在.jsp中显示图像和.css文件
我有一个文件FixHome.jsp,它试图显示style.css中的徽标和格式。但是,当我运行.jsp文件时,图像不会出现,并且stye.css文件的格式也没有实现 文件位置位于FixConnections项目下,如下所示: /WebContent/FixHome.jsp /WebContent/Resources/style.css /WebContent/Resources/needhamlogo2.bmp 我正在使用Eclipse并运行Tomcat7.0如何在.jsp中显示图像和.css文件,jsp,contextpath,Jsp,Contextpath,我有一个文件FixHome.jsp,它试图显示style.css中的徽标和格式。但是,当我运行.jsp文件时,图像不会出现,并且stye.css文件的格式也没有实现 文件位置位于FixConnections项目下,如下所示: /WebContent/FixHome.jsp /WebContent/Resources/style.css /WebContent/Resources/needhamlogo2.bmp 我正在使用Eclipse并运行Tomcat7.0 <html> <
<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文件。只需使用相对的HREF:
href="Resources/style.css"
或者,添加一个前导斜杠。contextPath只返回一个字符串,因此您的href呈现如下内容:
href="ctxt/Resources/style.css"
当您需要以下各项之一时:
href="/ctxt/Resources/style.css"
href="Resources/style.css"
尝试使用默认的servlet see doc 在jsp中(示例)
在web.xml中(示例)
违约
*.css
我尝试了href=“Resources/style.css”
但是它仍然没有在页面上生效。可能还有其他问题吗?难道你不能检查html中呈现的内容,只需查看html源代码。然后检查呈现的URL是否可以访问。它现在可以工作了。似乎我必须重新启动eclipse才能使其生效。非常感谢。
<link href="css/custom.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>