Meine Ordnerstruktur ist webapp-->resource--> images
.Das Bild wird nicht im Projektverzeichnis gespeichert
Hier ist mein Code:
public String addProductPost(@ModelAttribute("products") Product product, HttpServletRequest request) {
productDao.addProduct(product);
System.out.println(product);
MultipartFile productImage = product.getProductImage();
String rootDirectory = request.getSession().getServletContext().getRealPath("/");
path = Paths.get(rootDirectory +"webapp/resources/image"+ product.getProductId()+".png");
if (productImage !=null && !productImage.isEmpty()) {
try {
productImage.transferTo(new File(path.toString()));
/*Files.copy(Paths.get(productImage.toString()), path);*/
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Product image saving failed ", e);
}
}
Was passiert, wenn das 'try {}' derzeit ausgeführt wird? Hast du eine Ausnahme? – halfer