简体   繁体   English

Spring Boot 不将 src/main/resources 路径中的图像加载到 jsp 中

[英]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/**

Read more from here这里阅读更多

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 。

Spring Boot automatically maps static folder in the resources to serve static content. Spring Boot 自动映射资源中的静态文件夹以提供静态内容。 Just put images like this:只需放置这样的图像: 在此处输入图片说明

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

相关问题 如何在 spring boot 中将图像文件保存在 src/main/resources/images 中? - How to save image file in src/main/resources/images in spring boot? Spring Boot不提供src / main / resources / public目录中的某些图像 - Spring boot doesn't serve some of the images from the src/main/resources/public directory Spring Boot 1.4测试从主资源加载yaml文件 - Spring Boot 1.4 test loading yaml file from main resources 从/ src / main / resources加载文件 - Loading file from /src/main/resources Spring启动测试没有从src / main / resources中获取hbm.xml文件 - Spring boot test not picking up hbm.xml files from src/main/resources Liquibase 未从 Spring Boot 中的现有数据库在 src/main/resources 文件夹中生成 changeLog 文件 - Liquibase not generating changeLog file in src/main/resources folder from existing DB in Spring Boot 如何在 Spring Boot 中访问 src/main/resources/ 文件夹中的资源文件 - How to access a resource file in src/main/resources/ folder in Spring Boot 如何使用Spring MVC在src / main / webapp / resources中上传图像 - How to upload images in src/main/webapp/resources with spring MVC 从 spring-MVC 中的 src/main/resources/.. 读取资源 - Reading resources from src/main/resources/.. in spring-MVC 从 java 代码看不到 src 主资源中的 Spring 引导映像 - Spring boot images in src main resourcer aren't visible from java code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM