title: Java webapp: adding a content-disposition header to force browsers "save as" behavior
body: <p>Even though it's not part of HTTP 1.1/RFC2616 webapps that wish to force a resource to be <strong>downloaded</strong> (rather than displayed) in a browser can use the <code>Content-Disposition</code> header like this:</p>
  
  <pre><code>Content-Disposition: attachment; filename=FILENAME
  </code></pre>
  
  <p>Even tough it's only defined in RFC2183 and <em>not</em> part of HTTP 1.1 it works in most web browsers as wanted.</p>
  
  <p>So from the client side, everything is good enough.</p>
  
  <p>However on the server-side, in my case, I've got a Java webapp and I don't know how I'm supposed to set that header, especially in the following case...</p>
  
  <p>I'll have a file (say called "<em>bigfile</em>") hosted on an Amazon S3 instance (my S3 bucket shall be accessible using a partial address like: <em>files.mycompany.com/</em>) so users will be able to access this file at <em>files.mycompany.com/bigfile</em>.</p>
  
  <p>Now is there a way to craft a <em>servlet</em> (or a <em>.jsp</em>) so that the <code>Content-Disposition</code> header is always added when the user wants to download that file?</p>
  
  <p>What would the code look like and what are the gotchas, if any?</p>