简体   繁体   中英

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:

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

Path of my .jsp file:

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

and path of my image:

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.

文件夹结构

For example, maybe you have an Eclipse project with a src folder and an webcontent folder and an export folder and so on. In the picture you see my structure. In the views folder reside my jsp files. In the resources folder reside my css files and images and so on.

// 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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