[英]Picture does not load in spring
I'm fresher to spring. 我春天新鲜。 I try to add a profile picture. 我尝试添加个人资料图片。 I try to put the path in <img src="....">
. 我尝试将路径放在<img src="....">
。 When I inspect the elements, it shows the correct path, but in mouse over the element, its showing an additional url what i highlighted below. 当我检查元素时,它显示了正确的路径,但是在鼠标悬停在元素上时,它显示了我在下面突出显示的其他网址。
If i change to dashboard, its showing http://localhost:8080/pulseBeatMaster/dashboard/C :\\Users\\Varman\\workspace..... 如果我更改为仪表板,则显示http:// localhost:8080 / pulseBeatMaster / dashboard / C :\\ Users \\ Varman \\ workspace .....
If i change to feedback, its showing http://localhost:8080/pulseBeatMaster/feedback/C :\\Users\\Varman\\workspace..... 如果我更改为反馈,则显示http:// localhost:8080 / pulseBeatMaster / feedback / C :\\ Users \\ Varman \\ workspace .....
Actually the dashboard,feedback are mapped in controllers 实际上仪表板,反馈都映射在控制器中
@RestController
@RequestMapping(value="/dashboard")
public class DashboardController {
}
If picture is not clear, 如果图片不清楚,
In src path 在src路径中
<img src="C:\\Users\\Varman\\workspace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp1\\wtpwebapps\\pulseBeatMaster\\uploads\\20171025150534.jpg"/>
in mouse over 在鼠标悬停
http://localhost:8080/pulseBeatMaster/dashboard/C:\Users\Varman\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\pulseBeatMaster\uploads\20171025150534.jpg
I'm trying to sort this problem out for three days using references, but i have filed. 我正在尝试使用参考来解决此问题三天,但是我已经提出了。 Thank in advance 预先感谢
Actually when we load the image it will get relative path, not absolute path . 实际上,当我们加载图像时,它将获得相对路径,而不是绝对路径 。 So we need two things. 所以我们需要两件事。
1) Configuration 1)配置
public class WebConfig extends WebMvcConfigurerAdapter{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/uploads/**").addResourceLocations("/uploads/"); // i upload files inside root/uploads folder
}
}
2) Get relative path in jsp 2)在jsp中获取相对路径
<img src="${pageContext.request.contextPath}/uploads/abc.jpg" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.