Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 图像源错误_Html_Spring_Spring Mvc_Thymeleaf - Fatal编程技术网

Html 图像源错误

Html 图像源错误,html,spring,spring-mvc,thymeleaf,Html,Spring,Spring Mvc,Thymeleaf,我正在尝试显示位于桌面文件夹中的图像。我的问题是,当我将source设置为image thymeleaf或spring引擎将localhost:8080附加到其路径时 <img alt="" src="/Users/abdullahtellioglu/Desktop/ZambakResimler/yarnartjeans.jpg"> 我不知道如何从路径中删除localhost:8080并使路径成为绝对路径 您所做的不是服务器应该如何工作。当您想从您的web应用程序中提供某些资源时,

我正在尝试显示位于桌面文件夹中的图像。我的问题是,当我将source设置为image thymeleaf或spring引擎将localhost:8080附加到其路径时

<img alt="" src="/Users/abdullahtellioglu/Desktop/ZambakResimler/yarnartjeans.jpg">

我不知道如何从路径中删除localhost:8080并使路径成为绝对路径

您所做的不是服务器应该如何工作。当您想从您的web应用程序中提供某些资源时,您需要将其添加到您的web应用程序资源中。下面是一个简单的示例,说明如何修复它

  • 转到文件夹
    src/main/resources
    ,创建一个名为
    static
    的文件夹
  • 在该文件夹下创建另一个名为
    img
    的文件夹,并在其中复制您的图像。所以我们现在会有这样的东西:

    src
       main
           resources
                   static
                        img
                           yarnartjeans.jpg.jpg
    
  • 现在转到thymeleaf HTML页面并使用

    <a href="product_detail.html">
        <img th:src="@{/img/yarnartjeans.jpg}" alt=""/>
    </a> 
    
    
    
  • 现在,HTML页面将正确加载图像


    祝你好运

    桌面不是获取你想要在Spring应用程序中使用的图像的合适位置。你最好把你的图片放在某个资源文件夹里
    src
       main
           resources
                   static
                        img
                           yarnartjeans.jpg.jpg
    
    <a href="product_detail.html">
        <img th:src="@{/img/yarnartjeans.jpg}" alt=""/>
    </a>