title: Spring Controller for PDF download, location.href,jQuery Modal and and IE8 headers
body: <p>I have a simplistic Spring MVC controller method to return a PDF :</p>
  
  <pre><code>@RequestMapping(value="/attachment/portfolios/{investorNum}/reports/{reportId}/periods/{reportingPeriod}")
      public ResponseEntity&lt;byte[]&gt;  getReportForDownload(@PathVariable String reportId, @PathVariable long investorNum, @PathVariable long reportingPeriod) throws IOException{
          InputStream in = servletContext.getResourceAsStream("/sample.pdf");
          final HttpHeaders headers = new HttpHeaders();
          //headers.setContentType(MediaType.valueOf("application/pdf"));
          headers.add("Content-Type", "application/pdf");
          headers.add("Content-disposition", "attachment; filename=abcd.pdf");
          return new ResponseEntity&lt;byte[]&gt;(IOUtils.toByteArray(in), headers, HttpStatus.CREATED);
      }
  </code></pre>
  
  <p>And a spring bytearray message converter : </p>
  
  <pre><code>&lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
         &lt;property name="messageConverters"&gt;
           &lt;util:list&gt;
                  &lt;bean id="byteArrayMessageConverter" class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/&gt;
           &lt;/util:list&gt;
           &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>And a jQuery modal box for download :</p>
  
  <pre><code>"Download" : function() {
   location.href = "./attachment/portfolios/2201/reports/DELINQSUM/periods/1137";
  }
  </code></pre>
  
  <p>The download button works fantastically fine in FF, Chrome but not in IE. IE says </p>
  
  <blockquote>
    <p>Internet Explorer cannot download 1137 from localhost.</p>
    
    <blockquote>
      <p>Internet Explorer was not able to open this Internet site.  The
      requested site is either unavailable or cannot be found.  Please try
      again later.</p>
    </blockquote>
  </blockquote>
  
  <p>I followed headers as in <a href="http://support.microsoft.com/kb/316431" rel="nofollow">http://support.microsoft.com/kb/316431</a> and <a href="http://chiragrdarji.wordpress.com/2008/01/28/internet-explorer-was-not-able-to-open-the-internet-site-the-requested-site-is-either-unavailable-or-can-not-be-foundplease-try-again-later/" rel="nofollow">2</a> but nothing happens and IE continues report the problem.</p>
  
  <p>Also, I am streaming the PDF for embedded display inside the modal with the below change and that works fine : </p>
  
  <pre><code>headers.add("Content-disposition", "inline; filename=abcd.pdf");
  </code></pre>
  
  <p>I am running this on a tomcat.</p>
  
  <p>Any help greatly appreciated.</p>