title: Servlet Real Path
body: <p>I am running a webapp under the directory blog. (e.g. www.example.com/blog).</p>
  
  <p>I would like to get the real filesystem path of a request.</p>
  
  <blockquote>
    <p>e.g. www.example.com/blog/test-file.html ->
    /usr/share/tomcat7/webapps/blog/test-file.html</p>
  </blockquote>
  
  <p>I tried the following:</p>
  
  <pre><code> public String realPath(HttpServletRequest request, ServletContext servletContext){
      String requestURI = request.getRequestURI();
      String realPath = servletContext.getRealPath(requestURI);
      return realPath;
  }
  </code></pre>
  
  <p>However this returns </p>
  
  <blockquote>
    <p>/usr/share/tomcat7/webapps/blog/blog/test-file.html</p>
  </blockquote>
  
  <p>What is the correct way to do this?</p>