java - How to change getRealPath("/") path from .metadata to WEB-INF -


i uploading image files application, want save them in web-inf, eclipse saving in .metadata folder .metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps.

please let me know can path web-inf3

@requestmapping(value = "/admin/productinventory/addproduct", method = requestmethod.post) public string addproduct(@modelattribute("product") product product,httpservletrequest request) {//httservlet- aswe need use toget thesessionpath     productdao.addproduct(product);     /////add image     multipartfile productimage= product.getproductimage();     string rootdirectory= request.getsession().getservletcontext().getrealpath("/"); //c:\users\avinash kharche\ecommerce_spring_neon\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\emusicstore\     path =paths.get(rootdirectory + "\\web-inf\\resources\\images\\" + product.getproductid()+".png");      //path =paths.get("c:\\users\\avinash kharche\\ecommerce_spring_neon\\emusicstore\\src\\main\\webapp\\web-inf\\resources\\images\\" + product.getproductid()+".png");       if(productimage!=null && !productimage.isempty()){         try{             productimage.transferto(new file(path.tostring()));         }catch(exception e){             e.printstacktrace();             throw new runtimeexception("product image saving failed",e);          }     }     /////     return "redirect:/admin/productinventory";  } 

i dont want use commented path

(//path =paths.get("c:\users\avinash kharche\ecommerce_spring_neon\emusicstore\src\main\webapp\web-inf\resources\images\" + product.getproductid()+".png");)

please let me know solution. thanks

here solution:

    @requestmapping(value = "/admin/productinventory/addproduct", method = requestmethod.post) public string addproductpost(@modelattribute("product") product product, httpservletrequest request) {     productdao.addproduct(product);      multipartfile productimage = product.getproductimage();     string rootdirectory = request.getsession().getservletcontext().getrealpath("/");     path = paths.get(rootdirectory + "/web-inf/resources/images/" + product.getproductid() + ".png");      if (productimage != null && !productimage.isempty()) {         try {             productimage.transferto(new file(path.tostring()));         } catch (exception e) {             e.printstacktrace();             throw new runtimeexception("product image saving failed", e);         }     }      return "redirect:/admin/productinventory"; } 

change path from:

path =paths.get(rootdirectory + "\\web-inf\\resources\\images\\" + product.getproductid()+".png"); 

to

path = paths.get(rootdirectory + "/web-inf/resources/images/" + product.getproductid() + ".png"); 

make sure same edit , delete functions. had same problem. version, worked on windows on mac, had change path shown above


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -