Java 如何在jsp页面中包含图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24304232/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:23:46  来源:igfitidea点击:

How to include an image in a jsp page?

javajspjakarta-eeservlets

提问by Renaud is Not Bill Gates

I'm developing a web application using Hibernate, Springand JSP.

我正在使用Hibernate,Spring和开发 Web 应用程序JSP

In my jsppage I included images as the following :

在我的jsp页面中,我包含了以下图像:

<img src="img/logo/logo.png" alt="">

but they are not displayed when I run my jsppage.

但是当我运行我的jsp页面时它们不会显示。

The jsppage is located in :

jsp页面位于:

WEB-INF/index.php

this jsppage calls three other pages in the same folder as the following :

jsp页面调用同一文件夹中的其他三个页面,如下所示:

<%@ include file="header.jsp" %>
    <%@ include file="sidebar.jsp" %>
    <%@ include file="main.jsp" %>

and images are located in :

和图像位于:

WEB-INF/img

How can I solve this problem ?

我怎么解决这个问题 ?

回答by Nirav Prajapati

It may be possible that the image not display because of some path problem so that provide full context path and try it will work for you

由于某些路径问题,图像可能无法显示,因此提供完整的上下文路径并尝试它对您有用

<img src="${pageContext.servletContext.contextPath}/img/logo/logo.png" alt="">

Try this one it maybe help you

试试这个它可能对你有帮助

回答by Santino 'Sonny' Corleone

This will work for you

这对你有用

<img src="../img/logo/logo.png" alt="">