Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cache file(pdf) in user's browser using Servlet -Cookie, or Session

843841Jul 23 2003 — edited Jul 25 2003
How can I save a file (pdf) in the cache of a browser (IE 6) in a user's computer? I am using Servlet and Tomcat 4.1.24. PDF file is sitting in server (remote computer) under a URL space.

The idea is to NOT to download the pdf file on user's computer (from the remote server) if the user has a cached copy of the pdf file and pdf file in the server is the same as the pdf file in the browser. If cached pdf is different from pdf in browser, or, if the user does not have that pdf file in cache, then download pdf file from the server.

Can I come up with a way to use Cookie class? Cookie class does not have an API which will let me save a file in it. I could have saved the pdf file in the Cookie with 999999999 setMaxAge. Is storing that pdf file in session the only choice? I do not see session serving my purpose - session should not be valid for a longgg duration e.g. week or month.

Also, how would I create a file whne I am given a URL to that file.

URL fileInServer = new URL("http://www.myDomain.com/myWebApp/PDF/my.pdf);
URLConnection conn = fileInServer.openConnection();

Does getContent() help and what are the steps after that?

Any help with the source code will be appreciated.

Thanks,
Sam
sgho@aol.com
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 22 2003
Added on Jul 23 2003
4 comments
481 views