Html 图像源错误
我正在尝试显示位于桌面文件夹中的图像。我的问题是,当我将source设置为image thymeleaf或spring引擎将localhost:8080附加到其路径时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应用程序中提供某些资源时,
<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
<a href="product_detail.html">
<img th:src="@{/img/yarnartjeans.jpg}" alt=""/>
</a>
祝你好运桌面不是获取你想要在Spring应用程序中使用的图像的合适位置。你最好把你的图片放在某个资源文件夹里
src
main
resources
static
img
yarnartjeans.jpg.jpg
<a href="product_detail.html">
<img th:src="@{/img/yarnartjeans.jpg}" alt=""/>
</a>