title: How to set response header in JAX-RS so that user sees download popup for Excel?
body: <p>I wrote code that generate Excel file using REST JAX-RS and I confirmed that the generated Excel file is in GlassFish server directory.</p>
  
  <p>But my goal is when user click on the button (which generate Excel .xls), I want download popup to show up asking user whether to save or open the .xls file just like any other web services doing for downloading any type of files.</p>
  
  <p>According to my search, the step is:</p>
  
  <ol>
  <li><p>generate Excel .xls (DONE)</p></li>
  <li><p>write the excel to stream </p></li>
  <li><p>in JAX-RS file, set response header to something like,</p>
  
  <p>String fileName = "Blah_Report.xls";
  response.setHeader("Content-Disposition", "attachment; filename=" + fileName);</p></li>
  </ol>
  
  <p>My question is I'm doing all of this in JAX-RS file and I don't have HttpServletResponse object available.</p>
  
  <p>According to the answer from 
  <a href="https://stackoverflow.com/questions/1493415/add-response-header-to-jax-rs-webservice">Add Response Header to JAX-RS Webservice</a></p>
  
  <p>He says:</p>
  
  <blockquote>
    <p>You can inject a reference to the
    actual HttpServletResponse via the
    @Context annotation in your webservice
    and use addHeader() etc. to add your
    header.</p>
  </blockquote>
  
  <p>I can't really figure what exactly that means without sample code..</p>