Q:

how to create a temporary file in /tmp from a servlet?

I am using File.createTempFile from within a Servlet (the createTempFile version with only prefix and suffix but without a File argument).
According to the javadoc this should create a file in the system's default temporary directory (in my case /tmp). Instead, the file gets created in /tmp/tomcat7-tomcat7-tmp/.
Why the strange temporary file location and how can I change it to the "normal" temporary file location for my system?

A:

Java uses system property java.io.tmpdir to get current temporary directory. As far as I remember one of the scripts that run tomcat sets this variable to what you mentioned. If it is imprtant for you you should re-write this variable. Try to grep tomcat scripts, find this place and override it. Probably you can  set JAVA_OPTS=$JAVA_OPTS java.io.tmpdir=/tmp or something like this when running tomcat. (Obviously the syntax depends on your OS). 

