0

I am building a JSF2.2 web application and server is GlassFish V5. I am looking to configure the directly where I could store the files uploaded my the users of the website.

I am using the following code to store the files in the server's (Mac) path of /var/gdf (gdf being the web app's context name).

The code that fails is part.write("/var/gdf/"+getFileName(part)); where part is an instance of javax.servlet.http.Part; And the code for getFileName(part) is as follows:-

private static String getFileName(Part part){
     String filename=null;
     for (String cd : part.getHeader("content-disposition").split(";")) {
          if (cd.trim().startsWith("filename")){
               filename=cd.substring(cd.indexOf('=')+1).trim();
          }
     }
     return filename;
}

However, with each reboot of the Glassfish server, I see the following error on the logs:

Severe: java.io.FileNotFoundException: /Users///glassfish5/glassfish/domains/domain1/generated/jsp/gdf/var/gdf/2O4A1012.JPG (No such file or directory)

Any suggestion would be highly appreciated.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Singam
  • 443
  • 3
  • 12
  • Looks like you forgot to add in the code you're using! Could you edit your post and add that in please? – Mike Aug 29 '18 at 20:00
  • Code that fails is part.write("/var/gdf/"+getFileName(part)); where part is an instance of javax.servlet.http.Part; And the code for getFileName(part) is a follows:-private static String getFileName(Part part){ String filename=null; for (String cd : part.getHeader("content-disposition").split(";")) { if (cd.trim().startsWith("filename")){ filename=cd.substring(cd.indexOf('=')+1).trim(); } } return filename; } – Singam Aug 29 '18 at 20:29
  • @Mike pl see my comments above. – Singam Aug 29 '18 at 20:34

0 Answers0