I have written a jsp page to display contents of pdf, but end up with ascii codes in jsp. I want to display the contents of pdf in jsp. Whats the part that I have missed. Wh
Supposing we completely ignore the advice against using a JSP (and as BalusC says - there are BETTER WAYS), here's an ugly and shameful little bodge that worked okay for me. It doesn't even set all the right headers, but here goes:
<%@ page import="java.io.File" %><%@ page import="org.apache.commons.io.FileUtils" %><%
File pdfFile = (File) request.getAttribute("pdf");
byte[] pdfByteArray = FileUtils.readFileToByteArray(pdfFile);
response.setContentType("application/pdf");
response.getOutputStream().write(pdfByteArray);
response.getOutputStream().flush();
%>
It's important ensure there are no new-lines (or other whitespace) outside the scriptlet tags.
They made me do it, okay?!