• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error while displaying PDF from IE

 
hpillai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all:
I am trying to launch PDF files from a JSP page. This works fine for Netscape but it is not launching the viewer from IE 5.01. The PDF file shows up on the screen with grabage characters. Do you have any idead why is this? Any solutions to this is really appreciated!
Below is the code
Thanks,
Hari
try{
response.setContentType("application/pdf");
/**
* retrieve the OutputStream to the client
* instead of using the JSPWriter/PrintWriter as this may
* bring in character encoding on the data
* So use OutputStream::write(byte[]) to send the data to client
* and flush it.
*/
OutputStream outstream = response.getOutputStream();
byte[] data = reader.readFile();
if(data == null)
{
throw new RuntimeException("Error Reading The Report File...");
}
outstream.write(data);
outstream.flush();
}catch(Exception e){}
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First order of business, your name is not following JavaRanch naming convertion. You might want to change it before the sheriff catch you.
And regarding your problem, it looks like IE is not setup correctly to startup Reader or the plugins is not setup.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I recall, you should also setContentLength( data.length ) for maximum compatability with various browsers.
Don't just flush the output stream, you should also close() it.
AND - NEVER NEVER NEVER
catch(Exception e){}
that is throwing away any possible clue you might have as to a malfunction!! Tch!
Bill

------------------
author of:
 
vikinsa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To set the response header you can use a lot of things like..

<%@ page contentType="application/pdf" %>
<% response.setHeader("Content-Type","application/pdf");%>
<% response.setContentType("application/pdf");%>
Originally posted by hpillai:
Hi all:
I am trying to launch PDF files from a JSP page. This works fine for Netscape but it is not launching the viewer from IE 5.01. The PDF file shows up on the screen with grabage characters. Do you have any idead why is this? Any solutions to this is really appreciated!
Below is the code
Thanks,
Hari
try{
response.setContentType("application/pdf");
/**
* retrieve the OutputStream to the client
* instead of using the JSPWriter/PrintWriter as this may
* bring in character encoding on the data
* So use OutputStream::write(byte[]) to send the data to client
* and flush it.
*/
OutputStream outstream = response.getOutputStream();
byte[] data = reader.readFile();
if(data == null)
{
throw new RuntimeException("Error Reading The Report File...");
}
outstream.write(data);
outstream.flush();
}catch(Exception e){}


------------------
Vikas Aggarwal
Technology Associate
http://www.vikinsa.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic