Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Displaying PDf in the browser with JSP

843840Nov 13 2007 — edited Nov 16 2007
Hi,
I am trying to open a pdf file with the help of JSP... the PDF file is comming but without any content...it is giving blank pages
My code is given below...can anyone figure out why its happening...


<%@ page import="java.io.*" %>

<%

response.setContentType("application/pdf");
response.setHeader("Content-Disposition","inline;filename=\"c:/test1.pdf\"");

File f = new File ("c:/test1.pdf");
InputStream in = new FileInputStream(f);
ByteArrayOutputStream out1 = new ByteArrayOutputStream();
int size = 0;
byte[] b = new byte[1024];

while ((size = in.read(b, 0, 1024)) > 0) {
out1.write(b, 0, size);
}

response.reset();
response.setContentLength(out1.size());
response.getWriter().write(new String(out1.toByteArray()));

%>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 14 2007
Added on Nov 13 2007
15 comments
2,576 views