【发布时间】:2023-03-03 00:26:01
【问题描述】:
我正在使用 Spring mvc 创建一个图像上传应用程序。我成功地将图像保存在外部文件夹中。保存图片的代码是这样的:
MultipartFile productImage = product.getProductImage();
path= Paths.get("/oms/images/"+product.getProductName()+".jpg");
System.out.println(path.toString());
if(productImage!=null && !productImage.isEmpty()){
try {
productImage.transferTo(new File(path.toString()));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Product Image Saving Failed ",e);
}
}
图像已成功保存到该外部文件夹中。但是当我尝试将相同的图像显示到 jsp 文件中时,我最终得到了这个错误....
http://localhost:8081/oms/images/Ss.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8081/oms/images/pup.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
显示图片的代码是这样的……
<img src="<c:url value="/oms/images/${product.productName}.jpg"/>"/>
我看到了更多关于同一个问题的链接,但大多数问题是将图像保存到与 webapp 不同的目录中(显然)!
我错过了什么吗?如何将外部资源添加到 Spring 中?我应该怎么做才能将用户添加的图片显示到jsp页面中?
【问题讨论】:
标签: jsp spring-mvc image-uploading