The Artima Developer Community
Sponsored Link

Java Answers Forum
Java servlet - clear cache while Outputting PDFs

3 replies on 1 page. Most recent reply: Jul 24, 2002 1:10 PM by Jay Kandy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Zvi

Posts: 2
Nickname: steviehols
Registered: Jul, 2002

Java servlet - clear cache while Outputting PDFs Posted: Jul 23, 2002 9:08 AM
Reply to this message Reply
Advertisement
Hi,

I am using a Servlet to output PDF (Streams), i am facing a Browser cache problem in IE

i am setting Content type to PDF as follows...

response.setContentType("application/pdf")

When trying to disable the browser cache using any of the following the pdf file would not open! All I got was an error saying that adobe did not think the file existed!

response.setHeader("pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);


Can any one help me out in this.
Rgds..SH


Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: Java servlet - clear cache while Outputting PDFs Posted: Jul 23, 2002 3:07 PM
Reply to this message Reply
IE likes to know the size of the file before it displays anything. Try this:
Create an OutputStream for your PDF content.
ByteArrayOutputStream baos = new ByteArrayOutputStream();

Write all the PDF data to baos. Dont flush() anything yet. Just before you end service() method, use this:
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();

where response is your servlet's HttpServletResponse
Hope that helped,
Jay

Zvi

Posts: 2
Nickname: steviehols
Registered: Jul, 2002

Re: Java servlet - clear cache while Outputting PDFs Posted: Jul 24, 2002 8:00 AM
Reply to this message Reply
Im afraid that did not work - same error.
I think it is to do with ie5.5. but not sure..any other ideas?
cheers..SH

Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: Java servlet - clear cache while Outputting PDFs Posted: Jul 24, 2002 1:10 PM
Reply to this message Reply
Hmmmm what could be wrong?
1. Does it work in Netscape or with a FileOutputStream?
2. This is when you really wish for an exception! Post them if you got any.
3. Which library are you using?

Flat View: This topic has 3 replies on 1 page
Topic: Jrun Installation at SunOS Previous Topic   Next Topic Topic: tree menu--IMPORTANT

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use