title: How to serve a file with JSP?
body: <p>This may sound totally stupid, but is a case of real life :( </p>
  
  <p>I'm able to display a HTML table with a "virtual" link name.</p>
  
  <p>Something like this:</p>
  
  <pre><code>Xyz description   &lt;a href="docId=123"&gt;document.doc&lt;/a&gt;
  
  Xyz description  &lt;a href="docId=456"&gt;documentB.doc&lt;/a&gt;
  
  Xyz description  &lt;a href="docId=798"&gt;documentC.doc&lt;/a&gt;
  </code></pre>
  
  <p>This doc id represents an id in the database ( for these docs are stored in a blob as byte[] ) </p>
  
  <p>Anyway. I'm able to get that id, query the database and retrieve the byte[] ( and even store it in a tmp file ) </p>
  
  <p>What I can't figure out how to do, is, that when the user click on the link ( and after I perform the db retrieval ) "serve" the byte[] to the user. </p>
  
  <p>Now the very worst part, and what makes me ask this question here is, I need to do this with JSP only ( no servlet )  and without 3rd party libraries ( just... don't ask me why I hate it too ) </p>
  
  <p>So. How do I serve in a jsp the binary content of a byte array stored in the server file system </p>
  
  <p>My first guest is: </p>
  
  <pre><code>&lt;%
  InputStream read // read the file form the fle system 
  response.getOutputStream().write( theBytesReader );
  %&gt;
  </code></pre>
  
  <p>Am I close to the solution? </p>
  
  <p>Would this work to the client as if he had clicked really in the server for a real file?</p>
  
  <p>Thanks in advance. </p>