title: GWT: Get URL of file located on server
body: <p>I am developing an web application which can upload/download a file from client to PostgreSQL database server via GWT RPC call.</p>
  
  <p>I managed to create an upload servlet which store desired file(choosed by user via FileUpload widget) to Glassfish "TEMP" directory => then i used SQL command:</p>
  
  <pre><code>INSERT INTO table VALUES ('"+name+"',lo_import('"+f.getCanonicalPath()+"\\TEMP\\"+name+"'),...) 
  </code></pre>
  
  <p>which put that file into database. This works pretty good.</p>
  
  <p>Problem occurs when i want to download file from server to client. First i need to put the file back to TEMP dir with SQL command lo_export(...) -> this didn't work (some ERROR when creating a server file, permission denied), so i put the file manually to TEMP dir.</p>
  
  <p>Question is how can i display that file which is stored on server in TEMP dir?</p>
  
  <ul>
  <li>my path to glassfish server temp dir:C:\Program Files (x86)\glassfish-3.1\glassfish\domains\domain1\TEMP\example.pdf</li>
  <li>when deploying app url looks like: <code>http://localhost:8080/AppName/</code></li>
  <li>i tried something like that: Window.open("http://localhost:8080/AppName/TEMP/example.pdf", "_blank", "enabled")</li>
  </ul>
  
  <p>My CODE:
  Client side:</p>
  
  <pre><code>String link = GWT.getModuleBaseURL() + "filedownloadservlet";
  Window.open(link,event.getSelectedItem().getText(),"enabled");
  </code></pre>
  
  <p>so i pass to servlet located on server side a link and a file name...am i right ?</p>
  
  <p>Server side:</p>
  
  <pre><code>public class FileDownloadServlet extends HttpServlet {
      private String path = "TEMP//"; // Your absolute path
      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {             
  
      String filename = req.getParameter("filename");
      System.out.println(filename); // THIS IS NULL value
  
      File userManualFile = new File(path + filename);
      // You can fetch a Blob from the database instead.
  
      ServletOutputStream servletOutputStream = resp.getOutputStream();
      resp.setContentType("application/pdf");
      resp.addHeader("content-disposition", "attachment; filename=skuska.pdf");
  
      FileInputStream fileInputStream = new FileInputStream(userManualFile);
  
      IOUtils.copy(fileInputStream, servletOutputStream);
      servletOutputStream.flush();
  </code></pre>
  
  <p>When i press a file in Tree widget it shows me a new browser window with this error: </p>
  
  <pre><code>java.io.FileNotFoundException: TEMP\null (The system cannot find the file specified)
  </code></pre>