This question may betray my total lack of understanding, so be it, I guess. Trying the following code to display an image once the JSP page is running on Tomcat. Note, it's the tag that isn't working for me:
这个问题可能会背叛我完全缺乏理解,所以不管怎样,我猜。在Tomcat上运行JSP页面后,尝试以下代码来显示图像。注意,这是不适合我的标签:
<%@ 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>
All I get is the blue image question-mark symbol in the top left instead of my image. Link should be viewable here: http://postimage.org/image/drnl831pz/
我得到的只是左上角的蓝色图像问号符号而不是我的图像。链接应该可以在这里查看:http://postimage.org/image/drnl831pz/
Can anyone steer me in the right direction?
任何人都可以引导我朝着正确的方向前进吗?
3 个解决方案
#1
0
First you need to confirm that the image file is in the war file. Once you're sure it's there try removing the "WebContent" from the url in the JSP
首先,您需要确认图像文件是否在war文件中。一旦你确定它在那里尝试从JSP中的url中删除“WebContent”
#2
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
src-attribute的值缺少应用程序的上下文。现在主机名用作上下文根,因此浏览器使用错误的URL,例如HTTP://本地主机: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属性并加载图像,假设1)它在战争中2)它位于战争中的WebContent目录中:
src="${pageContext.request.contextPath}/WebContent/GBGeoQuestLogo.gif"
#3
0
I think your context path is Lab4/WebContent and your image is in WebContent. So in this case you can get image by,
我认为您的上下文路径是Lab4 / WebContent,您的图像位于WebContent中。所以在这种情况下你可以得到图像,
src="${pageContext.request.contextPath}/GBGeoQuestLogo.gif"
It will search image in WebContent because your Context path is Lab4/WebContent. If still have problem than in browser View Pagesource and verify the Image path
它将在WebContent中搜索图像,因为您的上下文路径是Lab4 / WebContent。如果仍然有问题,请在浏览器View Pagesource中验证图像路径
Thank you
#1
0
First you need to confirm that the image file is in the war file. Once you're sure it's there try removing the "WebContent" from the url in the JSP
首先,您需要确认图像文件是否在war文件中。一旦你确定它在那里尝试从JSP中的url中删除“WebContent”
#2
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
src-attribute的值缺少应用程序的上下文。现在主机名用作上下文根,因此浏览器使用错误的URL,例如HTTP://本地主机: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属性并加载图像,假设1)它在战争中2)它位于战争中的WebContent目录中:
src="${pageContext.request.contextPath}/WebContent/GBGeoQuestLogo.gif"
#3
0
I think your context path is Lab4/WebContent and your image is in WebContent. So in this case you can get image by,
我认为您的上下文路径是Lab4 / WebContent,您的图像位于WebContent中。所以在这种情况下你可以得到图像,
src="${pageContext.request.contextPath}/GBGeoQuestLogo.gif"
It will search image in WebContent because your Context path is Lab4/WebContent. If still have problem than in browser View Pagesource and verify the Image path
它将在WebContent中搜索图像,因为您的上下文路径是Lab4 / WebContent。如果仍然有问题,请在浏览器View Pagesource中验证图像路径
Thank you