P
P
pimmpo2019-11-24 13:00:09
Java
pimmpo, 2019-11-24 13:00:09

How to display images in Spring MVC?

I build the application using @SpringBootApplication, I managed to connect the styles in the index.jsp file

<style>
        <%@include file='../css/main.css' %>
</style>

However, it doesn’t work to display the image, when you try to access the image through the address bar localhost:8080/img/gmail.png , a message is displayed in the browser console that the image was not found
5dda54843063b441866272.png
https://github.com/pimmpo/BMOproject_springboot

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2019-11-24
@pimmpo

Greetings!
There can be various reasons for this... I also run into this sometimes when working with Spring Boot.
1) Use Rebuild Project. I don't know why, but with a simple restart of the application, static files may not be loaded. Accordingly, in the browser console in the "network" tab - 404 error.
2) Check if your resources are included in the application. Maybe the images are physically missing
3) Check the path to your resources. For example, in my Spring Boot, all static is stored in
/resources/static/css
/resources/static/js
/resources/static/images , etc.
To put it simply, take a look at your project settings and its structure....

R
Renat_F, 2020-04-09
@Renat_F

Had the same problem. I just wanted to display a picture in the index.html template.
Placed it in a folder /resources/static/images- and specified the path "images/имя_моего_файла"in index.html.
It worked, thanks for the tip!
5e8f3b5d6c7c4499216030.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question