0

这个问题可能会暴露我完全缺乏理解,我想就这样吧。一旦 JSP 页面在 Tomcat 上运行,尝试使用以下代码显示图像。请注意,这是对我不起作用的标签:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>George Brown GeoQuest - Welcome</title>
</head>
<body>
<img alt="logo" src="WebContent/GBGeoQuestLogo.gif">

</br>
<h1>Welcome, GB Geoquest Team!</h1>
<form action="/Lab4">
    <label>Team Name:
        <input type="text" name="name">
    </label><br>
    <input type="submit" value="Login">
    <input type="reset" value="Reset">
</form>
</body>
</html>

我得到的只是左上角的蓝色图像问号符号,而不是我的图像。链接应该在这里可见:http: //postimage.org/image/drnl831pz/

谁能引导我朝着正确的方向前进?

4

3 回答 3

0

我认为您的上下文路径是 Lab4/WebContent 并且您的图像在 WebContent 中。因此,在这种情况下,您可以通过以下方式获取图像,

src="${pageContext.request.contextPath}/GBGeoQuestLogo.gif"

它将在 WebContent 中搜索图像,因为您的上下文路径是 Lab4/WebContent。如果仍然有问题而不是在浏览器中查看 Pagesource 并验证图像路径

谢谢

于 2012-10-01T08:24:09.847 回答
0

首先需要确认镜像文件在war文件中。一旦您确定它存在,请尝试从 JSP 中的 url 中删除“WebContent”

于 2012-09-30T21:21:12.407 回答
0

The value of the src-attribute is missing the context of the application. Now the hostname is used as the context root, so browser uses the wrong url, e.g. http://localhost:8080/WebContent/GBGeoQuestLogo.gif

Add the context root to the src attribute and the image will be loaded, assuming 1) it's inside the war 2) it's located in WebContent-directory in the war:

src="${pageContext.request.contextPath}/WebContent/GBGeoQuestLogo.gif"

于 2012-09-30T21:26:57.180 回答