Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy download popup window in browser not showing up when using JAX-RS v.s. standard servlet?
    text
    copied!<p>When I try using <code>standard servlet approach</code>, in my browser the popup window shows up asking me whether to open .xls file or save it.</p> <p>I tried the exactly same code via <code>JAX-RS</code> and <strong>the browser popup won't show up somehow.</strong> Has anyone encounter this?</p> <p><strong>JAX-RS way that won't display popup:</strong></p> <pre><code>@Path("excellaTest") public class ExcellaTestResource { @Context private UriInfo context; @Context private HttpServletResponse response; @Context private HttpServletRequest request; public ExcellaTestResource() { } @Path("horizontalProcess") @GET //@Produces("application/vnd.ms-excel") @Produces("application/vnd.ms-excel") public void getProcessHorizontally() { try { URL templateFileUrl = this.getClass().getResource("myExcelTemplate.xls"); String templateFilePath = URLDecoder.decode(templateFileUrl.getPath(), "UTF-8"); String outputFileDir = "MasatoExcelHorizontalOutput"; ReportProcessor reportProcessor = new ReportProcessor(); ReportBook outputBook = new ReportBook(templateFilePath, outputFileDir, ExcelExporter.FORMAT_TYPE); ReportSheet outputSheet = new ReportSheet("myExcelSheet"); outputBook.addReportSheet(outputSheet); reportProcessor.addReportBookExporter(new OutputStreamExporter(response)); reportProcessor.process(outputBook); System.out.println("done!!"); } catch(Exception e) { System.out.println(e); } return; } }//end class class OutputStreamExporter extends ReportBookExporter { private HttpServletResponse response; public OutputStreamExporter(HttpServletResponse response) { this.response = response; } //ReportProcessor output() //This method is call when ReportProcessor process() is invoked. //The Workbook from POI API can be used to write to stream @Override public void output(Workbook book, BookData bookdata, ConvertConfiguration configuration) throws ExportException { //TODO write to stream try { response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=masatoExample.xls"); book.write(response.getOutputStream()); response.getOutputStream().close(); System.out.println("booya!!"); } catch(Exception e) { System.out.println(e); } } }//end class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload