title: How to download files on server to local machine using JSP
body: <p>Lot of research and hard work but still not getting the solution.I have one web application which is hosted on company server on which I am running my tomcat and web application inside tomcat. I am not being able to download the files located on server within specific folder.</p>
  
  <p>JSP code here below </p>
  
  <pre><code>&lt;%@ page language="java" contentType="text\html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1" import="java.io.File,java.io.IOException,java.util.*,java.io.*,java.text.SimpleDateFormat"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script src="//code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
  &lt;script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"&gt;&lt;/script&gt;
  &lt;meta http-equiv="Content-Type" content="text\html; charset=ISO-8859-1"&gt;
  &lt;script type="text/javascript"&gt;
  function downloadPDF(_var)
     {
      var docLocation = "path same as given below of variable 'filename'"+_var;
      window.open(docLocation,"resizeable,scrollbar");           
     }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;%
       String filename = "path of folder on server outside of tomcat directory(i.e outside of project foler)";
       File f = new File(filename); // current directory
       File[] files = f.listFiles();  
       for (File file : files) { 
         if (file.isDirectory()) {  
            //System.out.print("directory:");
         } else {
   %&gt;
   &lt;a href="#" target="" onclick="downloadPDF('&lt;%=file.getName()%&gt;')"&gt;&lt;br&gt;&lt;%= file.getName()+"_"+currentDate%&gt;&lt;/a&gt;
   &lt;%  
      } 
   } 
   %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>