wood burning stoves 2.0*
The moose likes Servlets and the fly likes Error while displaying PDF from IE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error while displaying PDF from IE" Watch "Error while displaying PDF from IE" New topic
Author

Error while displaying PDF from IE

hpillai
Greenhorn

Joined: May 14, 2001
Posts: 2
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

Joined: Mar 20, 2001
Posts: 210

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

Joined: Mar 22, 2000
Posts: 12809
    
    5
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

Joined: Apr 18, 2001
Posts: 46
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


Vikas Aggarwal<BR>Technology Associate<BR>http://www.vikinsa.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while displaying PDF from IE