Java 如何从文件夹在jsp页面中添加图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24848167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i add a image in jsp page from a Folder?
提问by Aditya
I have following directory of my project(in Eclipse)as below
我的项目目录(在 Eclipse 中)如下
WebContent | --Image | --logo.jpg --WEB-INF | --web.xml --lib --index.jsp --WebPage | --sayan.jsp
I want to add logo.jpg in both index.jsp and sayan.jsp page. I do this in the following method
我想在 index.jsp 和 sayan.jsp 页面中添加 logo.jpg。我用以下方法做到这一点
for index.jsp,
对于 index.jsp,
<img src="/Image/logo.jpg" />
and for sayan.jsp,
而对于 sayan.jsp,
<img src="../Image/logo.jpg" />
But in both case image does not appear in webpages.How can I load logo.jpg image in both pages?
但在这两种情况下图像都不会出现在网页中。如何在两个页面中加载 logo.jpg 图像?
采纳答案by Jens
Try : <img src="${pageContext.request.contextPath}/Image/logo.jpg" />
尝试 : <img src="${pageContext.request.contextPath}/Image/logo.jpg" />