title: Setting up a file for download on a tomcat server.
body: <p>I'm generating a .docx file server-side. I have it saved to a tmp directory, as follows:</p>
  
  <pre><code>docx.createDocx(System.getProperty("java.io.tmpdir") + "/example_title");
  </code></pre>
  
  <p>(I can confirm that this indeed works, the file is stored in /tmp/tomcat6-tmp/</p>
  
  <p>And I want the user to be able to download the created file. I have tried the following:</p>
  
  <pre><code>out.println("&lt;a href = '"+System.getProperty("java.io.tmpdir") + "/example_title.docx"+"'&gt;Here ya go!&lt;/a&gt;");
  </code></pre>
  
  <p>But that does not work. It directs me to <a href="http://localhost:8080/tmp/tomcat6-tmp/example_title.docx" rel="noreferrer">http://localhost:8080/tmp/tomcat6-tmp/example_title.docx</a> . This is obviously the wrong way to do this, but how does one create files on the server for the user to download using Tomcat?</p>
  
  <p>Thank you,
  Dara</p>
  
  <p>EDIT: Got it, for anyone that's interested:</p>
  
  <pre><code>public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      response.setContentType("application/msword");
      response.setHeader("Content-Disposition", "attachment; filename=\"consolidatedReport.docx\"");
  
      // Load the template.
      // Java 5 users will have to use RhinoFileTemplate instead
      CreateDocx docx = new CreateDocx("docx");
  
      String text = "Lorem ipsum dolor sit amet.";
  
      HashMap paramsTitle = new HashMap();
      paramsTitle.put("val", "1");
      paramsTitle.put("u", "single");
      paramsTitle.put("sz", "22");
      paramsTitle.put("font", "Blackadder ITC");
  
      docx.addTitle(text, paramsTitle);
      docx.createDocx(System.getProperty("java.io.tmpdir") + "/example_title");
  
      FileInputStream a = new FileInputStream(System.getProperty("java.io.tmpdir") + "/example_title.docx");
      while(a.available() &gt; 0)
        response.getWriter().append((char)a.read());
  }
  </code></pre>