title: Upload file to directory on server using Java and JSP - can't get path right
body: <p>On my vps, I want to upload a file to the Logos directory. 
  The directory structure is as follows on my vps -<br>
  /home/webadmin/domain.com/html/Logos</p>
  
  <p>When a file is uploaded through my jsp page, that file is renamed, and then I want to put it into the Logos directory.... but I can't seem to get the path right in my servlet code.</p>
  
  <p>Snippet of servlet code - </p>
  
  <pre><code>String upload_directory="/Logos/"; // path to the upload folder
  
  File savedFile = new File(upload_directory,BusinessName+"_Logo."+fileExtension);
  
  //.....
  //file saved to directory
  //.....
  </code></pre>
  
  <p>I've tried many variations, but still fail. What is the proper way to specify the path?</p>
  
  <p><b>Edited</b><br>
  The problem with using getServletContext() is that it returns the path to the directory where Tomcat and my webapp is...whereas I want to reach the directory where my html and image files are - under the root directory of the vps. How do I specify that path?</p>
  
  <pre><code>    String server_path = getServletContext().getRealPath("/"); // get server path.                      
  
      //server_path = /opt/tomcat6/webapps/domain.com/
  
      String upload_directory = "Logos/"; // get path to the upload folder.
  
      String complete_path = server_path + upload_directory; // get the complete path to the upload folder.
  
      //complete_path = /opt/tomcat6/webapps/domain.com/Logos/
  
      File savedFile = new File(complete_path,"NewLogo.jpg");
  
      //savedFile = /opt/tomcat6/webapps/domain.com/Logos/NewLogo.jpg 
  </code></pre>