• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display of PDF file through a servlet?

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to open a PDF file through a servlet without showing the download box. (A box which asks whether to open or to save it). The problem is the code executes fine in Netscape but in IE it gives a problem .With IE 5.5 the request is submitted but "refresh" needs to be clicked manually to bring up theb PDF file. This servlet is invoked on the click of a button.
However in Netscape it is working absolutely fine.
Can somebody tell me why it is not working for IE please??

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
public class PDFServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("application/PDF");
String header_info = req.getHeader("USER-AGENT");
if (header_info.indexOf("MSIE") != -1)
res.setHeader("Content-disposition", "inline; filename=wte.pdf");
else
res.setHeader("Content-disposition", "inline; filename=\\wte.pdf\\");
//String fileURL = "h:\\temp\\wte.pdf";
String hreffile = SessionManager.SessionHash.uom_get_data("VALUE", "hreffile");
String fileURL = "J:\\J2EE\\Cnapro\\Agentcenter\\inetprint\\" + req.getParameter("HREFFILE");
try {
File file = new File(fileURL);
byte[] byteContents = new byte[(int) file.length()];
FileInputStream in = new FileInputStream(fileURL);
// Read the file.
int retcd = in.read(byteContents);
ServletOutputStream out = res.getOutputStream();
BufferedOutputStream bos = null;
bos = new BufferedOutputStream(out);
bos.write(byteContents, 0, retcd);
} catch (Exception e) {
e.printStackTrace();
}
}
}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if this has anything to do with your problem, but you should also be setting content length in the headers. That is good general advice for serving any binary data file.
Bill
 
Anuj Anand
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That could be the reason because files which are over a certain size get displayed fine through the internet explorer (like over 10 KB) but small size files need a refresh to be clicked from IE browser...Any other coding advises...THe aim is to display a simple PDF file through the click of a button on a HTML page.
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic