title: Recommended way to save uploaded files in a servlet application
body: <p>I read <a href="https://stackoverflow.com/a/2663855/281545">here</a> that one should not save the file in the server anyway as it is not portable, transactional and requires external parameters. However, given that I need a tmp solution for tomcat (7) and that I have (relative) control over the server machine I want to know :</p>
  
  <ul>
  <li><p>What is the best place to save the file ? Should I save it in <code>/WEB-INF/uploads</code> (advised against <a href="https://stackoverflow.com/a/13617442/281545">here</a>) or someplace under <code>$CATALINA_BASE</code> (see <a href="https://stackoverflow.com/a/1047581/281545">here</a>) or ... ? The JavaEE 6 tutorial <a href="http://docs.oracle.com/javaee/6/tutorial/doc/glraq.html#gmhbq" rel="noreferrer">gets the path from the user</a> (:wtf:). NB : The file should not be downloadable by any means.</p></li>
  <li><p>Should I set up a config parameter as detailed <a href="https://stackoverflow.com/a/2663250/281545">here</a> ? I'd appreciate some code (I'd rather give it a relative path - so it is at least Tomcat portable) - <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/Part.html#write%28java.lang.String%29" rel="noreferrer"><code>Part.write()</code></a> looks promising - but apparently needs a absolute path</p></li>
  <li><p>I'd be interested in an exposition of the disadvantages of this approach vs a database/JCR repository one</p></li>
  </ul>
  
  <p>Unfortunately the <a href="http://balusc.blogspot.gr/2009/02/fileservlet-supporting-resume-and.html" rel="noreferrer">FileServlet</a>  by @BalusC concentrates on downloading files, while his <a href="https://stackoverflow.com/a/2424824/281545">answer</a> on uploading files skips the part on where to save the file.</p>
  
  <p>A solution easily convertible to use a DB or a JCR implementation (like <a href="http://jackrabbit.apache.org/frequently-asked-questions.html" rel="noreferrer">jackrabbit</a>) would be preferable.</p>