简体   繁体   English

使用什么路径以在 spring boot 中显示 .jsp 文件中的图像

[英]What path to use in order to show images in .jsp file in spring boot

I want to show image in my website(localhost), and in my .jsp file I have line that goes like this:我想在我的网站(本地主机)中显示图像,在我的 .jsp 文件中,我有这样的行:

<img src = "/images/myImage.png" alt = "image to be shown">

Path of my .jsp file:我的 .jsp 文件的路径:

webApp/src/main/webapp/WEB-INF/jsp/"my.jspFile" webApp/src/main/webapp/WEB-INF/jsp/"my.jspFile"

and path of my image:和我的形象的路径:

webApp/src/resources/static/images/"myImage.png" webApp/src/resources/static/images/"myImage.png"

what kind of path should u use in order to display this image on my webiste.你应该使用什么样的路径才能在我的网站上显示这个图像。 For now its only showing alternative text.目前它只显示替代文本。

You can use the JSTL to set a URL relative to your structure.您可以使用 JSTL 来设置相对于您的结构的 URL。

文件夹结构

For example, maybe you have an Eclipse project with a src folder and an webcontent folder and an export folder and so on.例如,也许您有一个 Eclipse 项目,其中包含一个 src 文件夹、一个 webcontent 文件夹和一个导出文件夹等等。 In the picture you see my structure.在图片中你可以看到我的结构。 In the views folder reside my jsp files.在视图文件夹中驻留我的 jsp 文件。 In the resources folder reside my css files and images and so on.在资源文件夹中存放我的 css 文件和图像等。

// Add this at the very top of your jsp-File
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

// Add a tag like this
<img src="<c:url value='/resources/img/apple-touch-icon.png'/>" alt="Icon" />

The path is relative to your webcontent folder where your jsp-files reside.该路径相对于您的 jsp 文件所在的 webcontent 文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM