I know this is a many time asked question. I have went through all of the answers but cannot find a working solution. I am trying to download a pdf file, and the code block in jsp is as below
but the the data is flushed into browser window like below
%PDF-1.4 %áéëÓ 2 0 obj <> endobj 3 0 obj <> /XObject <> /Font <> >> /MediaBox [0 0 612 792] /Annots [<> >> <> >> <> >> <> >> <> >>] /Contents 16 0 R >> endobj 16 0 obj <> stream xœµ]ÛŽ$9}Ÿ¯¨ ׎ðUBH,Ëð ÞB,h—ÿ—HgUwF
please help me on this.
<%
java.io.File file=new java.io.File("C:\\down\\personal\\Card.pdf");
java.io.InputStream in = new java.io.BufferedInputStream(new java.io.FileInputStream(file));
response.setHeader("Content-Disposition", "attachment; filename=empfile.pdf");
response.setContentType("application/pdf");
org.apache.commons.io.IOUtils.copy(in, response.getOutputStream());
response.flushBuffer();
%>
also am getting below error
12:57:32,068 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/business].[spring]] (http-/127.0.0.1:8080-7) JBWEB000236: Servlet.service() for servle spring threw exception: java.lang.IllegalStateException: JBWEB000028: getOutputStream() has already been called for this response