How to Get a Temporary Directory
The web container provides every web application with a private temporary directory. Its location is stored in the context attribute javax.servlet.context.tempdir. The specification leaves it open whether the server deletes the directory's content after a restart, so your application should be prepared for both cases.
File tmpDir = (File) getServletContext().getAttribute("javax.servlet.context.tempdir");
File privFile = new File(tmpDir, "myTempFile");
privFile.delete(); // delete file in case it already exists
// do something with privFile
privFile.delete(); // clean up (possibly in destroy)