[英]Spring boot not loading images from src/main/resources path into jsp
I have a image file inside我里面有一个图像文件
enter image description here在此处输入图片说明
Here is my configuration inside Configuration class.这是我在 Configuration 类中的配置。
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/**",
"classpath:/static/**", "classpath:/public/" };
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
Inside Jsp I am not able to load the image under div tag在 Jsp 中,我无法在 div 标签下加载图像
<div id="image">
<p>
<img src="/images/reviewCount.jpg" width="600" height="400" border="0" usemap="#chart">
</p>
I tried我试过了
1) To give absolute path like src/main/resources/static/images/reviewCount.jpg 1)给出绝对路径,如 src/main/resources/static/images/reviewCount.jpg
2) src="{/images}/reviewCount.jpg"
2)
src="{/images}/reviewCount.jpg"
Both the approaches went in a wine.这两种方法都在酒中。
Any one who can some shed light would be appreciated.任何可以阐明的人都将不胜感激。
TIA. TIA。
regards Vinod问候维诺德
You have to place all the images, css, js
files inside your webapp
folder.. ie webapp/resources
.您必须将所有
images, css, js
文件放在webapp
文件夹中。即webapp/resources
。
If you are packaging the application as a jar then dont use the src/main/webapp
this will only work with war packaging and it will be ignored by most build tools if you generate a jar.如果您将应用程序打包为jar,则不要使用
src/main/webapp
这仅适用于war打包,如果生成 jar,大多数构建工具将忽略它。
In Spring boot by default, resources are mapped on /**
but you can tune that via spring.mvc.static-path-pattern
.默认情况下,在 Spring boot 中,资源映射到
/**
但您可以通过spring.mvc.static-path-pattern
。 For instance, relocating all resources to /resources/**
can be achieved as follows:例如,将所有资源重定位到
/resources/**
可以实现如下:
spring.mvc.static-path-pattern=/resources/**
It is a typo.这是一个错字。 You have reviewCount.png in static/images folder and you are referring reviewCount.jpg from div tag.
您在 static/images 文件夹中有 reviewCount.png 并且您从 div 标签引用 reviewCount.jpg 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.