I've been trying to get IE11 to download a pdf file, but this seems to cause the browser to simply open a new window to render the pdf.
public void forceLoad () throws IOException {
OutputStream out = null;
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.sendRedirect("https://math.dartmouth.edu/archive/m19w03/public_html/Section5-2.pdf");
response.setContentType("application/octet-stream");
//response.setContentLength(len);
response.setHeader("Content-Disposition", "attachment; filename=\""+ "test.pdf" +"\"");
out = response.getOutputStream();
out.flush();
fc.responseComplete(); //we will need this or else JSF will attempt to render the response which would fail
return;
}