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

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
[email protected]

I am NOT creating this PDF file on the fly. This pdf file is sitting in the server (remote machine) under URL e.g. http://10.10.10.xxx:8081/myApp/PDF/my.pdf
I need to check if this pdf file is in the cache in user's computer (differnt machine than the server) and if the cached pdf is the same as the pdf in the server. If that file is not in the cache, or if they are not the same, then, I need to save the pdf file from the server into user's browser cache.
I am writing all that code in Servlet. I can save the file in session. I do NOT know how else can I cache the file, other than saving it in session. I can not think of any setHeader() which will let me save a file in user's browser cache. Headers like If-Modified-Since are of no help, as it does not let me compare file in browser cache with the file in server.
Also, how would I create a file, given a URL to that file.
URL fileInServer = new URL("http://www.myDomain.com/myWebApp/PDF/my.pdf");
URLConnection conn = fileInServer.openConnection();
Do I use getContent()? What are the steps after that?
Thanks,
Sam
[email protected]

Similar Messages

  • Move the Cache files for all user in the domain, which work with the PC

    Is there a possibility to chance the Cache file for all User.
    If i logon with a new user the Cache is written automatically in Proflie of the user.
    can configure to Java in such a way that with announce a user the Cache file get automatically moved to c:\temp.
    Thanks for your help

    oh, too bad, it is part of the requirement-we need to do it automatically through web.
    Any easier method to change the client machine deployment.properties through web?
    Need to deploy the application to thousands PC and the PC configuration may be different one by one.
    oldguy

  • Uploading the file to server from the browser using JSP

    I have facing difficulty while uploading the file from the browser using user interface to the server or to the database. As previousy i was working in coldfusion, i find it very easy there with cffile command, but i am confused how to do that in JSP
    please reply soon, as i am stuck in my project because of that
    Sarosh

    Check out http://www.jspsmart.com , They have a nice free upload api that can be used w/ JSPs or Servlets. I hear O'Reilly has a nice one too. May as well use someone elses if they've done it already.

  • Do I need all those media cache files in my user profile?

    Hello Forum,
    When I installed Win 7 and Adobe Production Premium on a 120Gig SSD, I made this mistake of not putting only the essential part of Windows on this System and Apps drive. (I have separate 1Tb HDDs for media and rendering, and work with compressed HD files).  I noticed that my user profile has grown enormous, to the point of filling up the SSD, and when I searched to see why, the main problem is a substantial accumulation of media cache files in the folder...
    user/App Data/Roaming/Common/Media Cache Files
    Judging by their names, sizes, and dates, they seem to pretty much replicate all my raw media files on my media HDD, from all the projects I've done since last summer. This folder is about 40 gigs.
    So what is the function of this media cache folder? Can I move it, or direct PP to put this stuff on some other drive than my SSD? Do I even need the contents of this folder? All my scratch files go to the F: Rendering HDD.
    Thanks.
    PS: If any of you have suggestions on how to move my user profiles off the boot/apps SSD to one of the HDDS, without reinstalling everything, I'm all ears.

    To follow up, I now see this is a product of running AME, and AME gives me options of where to put all this stuff. Can I just change those options to my F: Rendering Drive, and move the contents of this folder there?

  • Since upgrading to Firefox 4 I cannot get PDF files to open in the browser using Acrobat 9.0

    I have my Application options set to "Use Adobe Acrobat 9.0 (default)," yet clicking on a pdf link causes the file to be downloaded and opened outside of the browser.
    I've checked for missing plug-ins, but that only leads me to a download page for Adobe Reader 10, which should not be necessary since I already have the full version of Acrobat.

    In my case it's with .puz files, which are crossword puzzle files used by sites like the New York Times and read by the application AcrossLite. I went into preferences and tried to change the action for the file type from "Save File" to AcrossLite but it would not take. Set it instead to "Always Ask" and then in the dialogue box selected AcrossLite and "always do this" and it gave an unknown error.
    This is FF 4 on a Mac.

  • How to open a file (*.html,*.pdf) in new browser using servlet

    Dear Friends,
    I am having some files (*.html,*.pdf) in local drive , im getting the path whichy includes dir name + file dynamically, im using the following code
    response.sendRedirect(response.encodeRedirectURL(file))
    this is displaying the file in same window, now i want open in new window is there any method except java script like window.open("URL");
    Thanks in advance....
    Thangavel

    Hi Balu !
    Thanks for u r reply ,
    this is html code ok
    <a onclick="view()" >View </a>
    im callinig view function in java script
    function view()
    window.document.formname.submit()
    so it will submit the action URL which given in form ok
    filename contains full path ok
    in server side im sending as i told previously encoderURL(file) ok
    but im given target="_blank" as per ur suggestion in anger tag like
    <a target="_balnk" onclick="view()" >View </a> tag
    it is opening in new window the content which is displaying in jsp but not file
    pls give ur valueable suggestion .....
    Thanks in advance...
    Thangavel

  • EVDRE: refresh dimension cache files each time user saves or refreshes data

    Hi experts,
    We're facing a performance trouble with our input schedules, so we pretend to decrease response times.
    We've noticed an unexpected issue when users work with input schedules. Each time they save or refresh data into any input schedule, it seems to execute a dimension files refresh. Since they push Save buton till standard success message appears, we see diferent text messages in excel messages bar, in the bottom of excel window. And for a while, we can see a message where we can read "Load dimension cache".
    Does anyone know if this is an standar behaviour? Is there any way to avoid that, so we can decrease response time regarding input schedule performance?? Is there any dimension files refresh while we save data from an input schedule?
    Thanks in advance.

    I see these, too, running Fx12 on Windows 7. They are described in the (extremely voluminous!) about:cache interface as page thumbnails. I've attached some screen shots.
    The text is extremely difficult to see, so I don't know whether it is a serious privacy/security risk. I would be curious to know how long they linger.
    I think these support the Windows feature of showing a preview of a window or tab when you float over a taskbar button. (No idea whether there is a similar preview feature on Mac.) This feature is not enabled by default; users need to enable it in about:config. However, add-ons may be able to use the thumbnails because they have privileged access to the cache.
    (Note: This feature was added pursuant to [https://bugzilla.mozilla.org/show_bug.cgi?id=497543 497543 – Provide a thumbnail service]. It "landed" on or about Jan. 28, 2012, so its first appearance in a released version of Firefox might have been Fx12.)

  • How to display file content in browser using servlet..? urgent!!!

    hello,
    i am building a application for which when a user logs in he will we redirected to page where he will have one link ,with this link a file is associated.
    when user press that link he should be able to see that particular file in internet browser....
    now can anybody give me a code sample of how to display a file in browser....
    please reply me as soon as possible...

    thanks for your reply....
    but i don't want this....
    i want to read a file from disk into stream or buffer and from that again reading and printing in browser.....
    a servlet should be built for this....
    i wrote this but its not working
    ========================================================
    public class FilePrinting extends HttpServlet
         public void doPost(HttpServletRequest req,HttpServletResponse res)
              throws IOException,ServletException
              ServletOutputStream out=res.getOutputStream();
              res.setContentType("text/html");
              String fileURL="/mydomainWebApp/Test.htm";
              res.setHeader("Content-disposition","attachment; filename=" +="Test.htm" );
              BufferedInputStream bis=null;
              BufferedOutputStream bos=null;
              try
                   URL url = new URL( fileURL );
                   bis=new BufferedInputStream(url.openStream());
                   bos = new BufferedOutputStream(out);
                   byte[] buff = new byte[2048];
                   int bytesRead;
                   // Simple read/write loop.
                   while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                   bos.write(buff, 0, bytesRead);
              }catch(final MalformedURLException e)
                   System.out.println ( "MalformedURLException." );
                   throw e;
              }catch(final IOException e)
                   System.out.println ( "IOException." );
                   throw e;
              }finally
                   if (bis != null)
                        bis.close();
                   if (bos != null)
                        bos.close();
    =======================================================================
    please send me sample code if anyone have../...

  • How to display XML file as is it is in my browser using servlets???

    I have a question like my servlet receives an XML file in its request object. I just need display the same XML file as it is in my browser. How to do that? Please help me out. I have searched so many blogs, but i did not get right solution.
    My XML file file will be like this:
    <ns0:Http_Message_Type_Demo xmlns:ns0="http://abcdemo.com">
    <Name>A</Name>
    <RollNo>123</RollNo>
    <Address>a2</Address>
    </ns0:Http_Message_Type_Demo>
    Thnks

    You mean you want to see the XML source?
    You need to replace the characters '<' and '&' with corresponding entities '&lt;' and '&amp;'. You can use replaceAll, but do the ampersands first.
    Then I suggest you probably want to put them in a <PRE> block.

  • Creating flat files (.csv) in user defined directory using PL/SQL

    I need to extract data into a flat file (.csv) and store the flat file directly into a directory on local drive as specified by the user at runtime. I do not intend to use the UTL_FILE package. Is there a way put to do this?
    Thanks
    Amit.

    Hi Amit,
    Your users have any shared drive which every one can access? If so follow these steps.
    1> Allow users to select their destination location to an APEX item.
    2> On submit, save the user IP, destination location and user name to a database table.
    3> On submit, using JS, open XLS file template (+kept this template file in shared location+) The template should contain all the macros that will do the needful. I mean they should connect to database and should fill it with data and saving it to user specified location etc.
    Hope it helps.
    Cheers,
    Hari

  • How to display RTF File in Browser Using Servlets/JSPs

    Hi All,
    I have some RTF Files, which contains some data.
    The data needs to be displayed in the frame of jsp page .
    How i can display the RTF File Content using either servlets/jsps
    Can any body have idea on this.
    Help me out on this.
    With Regards
    Hari

    If you only need to display it, consider your HttpServletRequest just as byte stream. :) Just read from ServletInputStream and write it back into ServletOutputStream of HttpServletResponse.
    If you want to process incoming XML, please give some details first, what exactly you want to do. :)

  • How to display XML file in browser using Servlets?

    Hi My XML file is like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:purchase_order_MT xmlns:ns0="http://filetohttp.com">
    <ORDER_HEADER_IN>
    <purchase_date/>
    <purchase_group/>
    <purchase_org/>
    </ORDER_HEADER_IN>
    <vendor/>
    <ORDER_ITEMS_IN>
    <item>
    <storage_location/>
    <plant/>
    <quantity/>
    <material/>
    </item>
    </ORDER_ITEMS_IN>
    <ORDER_SCHEDULES_IN>
    <item>
    <delivery_date/>
    </item>
    </ORDER_SCHEDULES_IN>
    </ns0:purchase_order_MT>
    My Servlet receives this XML file and it should display the above XML as it is, How to do that?
    Please help me I have posted same question in many forums but i got no proper reply.
    Thanks a lot

    If you only need to display it, consider your HttpServletRequest just as byte stream. :) Just read from ServletInputStream and write it back into ServletOutputStream of HttpServletResponse.
    If you want to process incoming XML, please give some details first, what exactly you want to do. :)

  • Wanting to open a HTML document in users default browser using Menu Items

    I have a couple of Menu items that I want to open up various HTML documents.
    menuHelpItem.addActionListener(new ActionListener()
         public void actionPerformed(ActionEvent evt)
    });I've seen a couple of 'solutions' to people asking about opening files, but none even compiled never mind ran. It's in my parent program, and any solution needing to throw IOException (lots of things annoyingly seem to) that'll mean the listeners need to which never seems to work. Even if it did though, the class would have to and so would all the others. Messy.
    Best I've done is open up a new JEditorPane based on the url of the HTML files, but this is definately not good enough as the font, layout, links are all screwed and if I could fix it, it would no doubt take longer than I have.
    So basically, say you have a button, how do you make it open "resources/SearchHelp.html"?

    "http://www.google.com"; //
    Interesting. I changed my code to this:
    private void showHelp(String url)
         try
              String[] cmd = new String[5];
              cmd[0] = "cmd.exe";
              cmd[1] = "/C";
              cmd[2] = "rundll32";
              cmd[3] = "url.dll,FileProtocolHandler";
              cmd[4] = PronunciationDictionary.class.getResource(url).toString();
              Process process = Runtime.getRuntime().exec( cmd );
         catch (IOException e)
              JOptionPane.showMessageDialog(this, "Unable to load help file. Please try again.", "Help - Dictionary A'la Lewis", JOptionPane.INFORMATION_MESSAGE);
    }and I printed out PronunciationDictionary.class.getResource(url).toString(); before trying it and that worked fine. I click on the buttons but nothing happens, no error which is good, but nothing else either, which is bad. I thought maybe I was just doing it wrong, so I tried replacing it with just http://www.google.com but same thing, nothing happened at all.

  • Pass the text file name to the command prompt using servlet

    hi to all,
    I have a HTML page that takes the user inputs. Once the user clicks on the submit button on the HTML page, these values will be capture by a servlet and then store into a text file. A new text file is generated each time the user clicks on the submit button.
    Now, i need to call a command prompt window and then pass the text file name to another program for execution. Any idea how i can pass the text file name to the command prompt???
    Thanx a lot....
    kinki

    hi, thanx 4 ur reply.
    But i not onli want to display the file name on the Tomcat command prompt. I must also able to call up a program to execute the command. If i used System.out.println(); it onli display the value on the console windows. But not executing it... anyway where i can do it???.
    thanx...
    Kinki

  • How to display HTML response file in user's browser following submission of Livecycle form

    I have a PDF form created via Livecycle that does a HTTP submit to the webserver. The server returns a HTML 'submission receipt' page which is either opened in Acrobat or the user's web browser.
    Previously this process worked fine when submitting from adobe reader - the html receipt file would always automatically open OK in the user's browser. However, with newer versions of Reader (11.0.0+) I now get this error and no attempt to open the user's web browser:
    An error occurred during the submit process. Cannot process content of type text/html
    I realise why I get the error - Adobe reader can't display HTML files.
    What I don't understand is why it doesn't open the html file in the user's browser like it has been doing for years.
    Does anyone have any idea how I can fix this (without changing the response content type to PDF/FDF)?

    I had the same issue as you and we used FDF status, then eventually went with returning an XDP  that filled out a receipt section of the form.

Maybe you are looking for

  • Why will a Leopard backup DVD not work on G5.

    A couple of Leopard issues: 1, When I a make a dvd backup of my Leopard dvd using either Disk Utility or Toast it will work fine on the intel but will be spit out of the G5. The G5 cannot make double layer so I must rely on a computer that does! My G

  • Resource mismatch error in Acrobat Pro 6.0

    Since I installed the newest version of Acrobat Reader, my Acrobat (version 9) my Acrobat Pro 6.0 no longer works!! Upon launch I get a "Resource Mismatch" error. There is no other explanation or information as to why the program won't run.

  • Front Row versus iTunes

    Upgraded my G5 dual 1.8 tower to Leopard. Couldn't wait to use Front Row on the 30" Apple Cinema Display. Heart-broken to discover that all my movies and tv shows from my iTunes library are practically unwatchable when played through Front Row. The v

  • HT201272 How do you download a previous purchase that did not work?

    I purchased a song, but, when I went to play it, it do not play the whole song?

  • Unfortunately Messaging has stopped Droid Maxx

    I first noticed this issue last Friday, it has been occurring consistently since then. I can send text messages, however I can not receive. Several people have sent messages that never arrive. I also have had the phone for on about 3 months. Love thi