This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to clear the browser cache when I close my browser. 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 "How to clear the browser cache when I close my browser." Watch "How to clear the browser cache when I close my browser." New topic
Author

How to clear the browser cache when I close my browser.

Ratish Vichithran
Greenhorn

Joined: Feb 27, 2009
Posts: 9
My application shows payslips of employees. So when a user click on a link it generates the pdf for which I have added the following code,



But the problem here is that, it creates a PDF in the temporary folder.

Is there a way to delete the cache after the browser showing the pdf is closed?

I tried deactivating cache with the following code,



but it gave me an error saying the file could not be downloaded.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Nope. The file must be copied to the local system in order to be viewed and there is no setting to cause it to delete itself.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ratish Vichithran
Greenhorn

Joined: Feb 27, 2009
Posts: 9
Hi Bear Bibeault. Thanks for the reply...

But is there any way to avoid a Cache and also show a pdf using Content-Disposition as inline? . Because it is a security concern. Any other user using the work station can easily access the previous persons data.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Nope. It is the responsibility of the user to keep his data secure.
Ratish Vichithran
Greenhorn

Joined: Feb 27, 2009
Posts: 9
Ok let me put it this way. How will I show a pdf to the user and also adhere to security?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Let me put it this way: you can't!

If you want to show the file to the user, it must be downloaded to their system. After that, it's their responsibility.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Alternatives:
  • Don't use a PDF or anything that needs to be downloaded to their system. Just show it as a no-cached page.
  • Explore password-protecting the PDF.
  • Don't show it in the broswer at all; send it in email.

  •  
    Don't get me started about those stupid light bulbs.
     
    subject: How to clear the browser cache when I close my browser.