I tried to upload an image to tomcat and glassfish servers, Path I tried to set is as bellow
System.getProperty("user.dir")+ File.separator+"images"+File.separator;
System.getProperty("user.dir")
C:\Apache\Tomcat\bin
out/artifacts/CopywriteProtector_war)exploded/Resources/images
http://localhost/Resources/images/msg.jpg
You can get the root of your deployed application with
String root = getServletContext().getRealPath("/");
This will be the equivalent of the resources directory of your source code. Add the filepath of where you want your image to be. i.e.
String filePath = root + "images/msg.jpg";
Then you can created your writer from that path
BufferedWriter writer = new BufferedWriter(new FileWriter(filepath);
writer.write(objectToWrite);//or similar
You can then access the resulting file with
getServletContext().getResource(filePath); // as URL or
getServletContext().getResourceAsStream(filePath); // as InputStream
-- Tested and worked on Payara (an application server derived from Glassfish)