Prevent servlet from caching,

Discussion in 'Java' started by vinodh@uab.edu, Jan 6, 2005.

  1. Guest

    I am having problem with servlet caching. My Servlet keeps displaying
    previously cached image instead of an updated image. I tried out the
    following workarounds and was not successful.

    1. Set the following Response headers

    res.setDateHeader("Expires", 0);
    res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate,
    post-
    check=0, pre-check=0");
    res.setHeader("Pragma", "no-cache");

    2. Set HTML META TAG:

    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">

    Has anyone experienced a similar issue and can you share your
    worarounds. I even tried setting DateHeader as follows but no luck.
    res.setDateHeader("expires", System.currentTimeMillis()).
    thanks in advace
    vinodh
     
    , Jan 6, 2005
    #1
    1. Advertising

  2. Chris Guest

    > I am having problem with servlet caching. My Servlet keeps displaying
    > previously cached image instead of an updated image. I tried out the
    > following workarounds and was not successful.


    This problem is really a headache, because it's controlled by the user's
    browser, not your application. One reliable way to fix it is to change the
    name of the image each time it's updated.

    Hey, I just had another idea -- haven't tried it, though. Maybe you can add
    a random parameter to the image.

    <img src="myimage.gif?rand=<%=myrandomnumber%>">
     
    Chris, Jan 7, 2005
    #2
    1. Advertising


  3. > This problem is really a headache, because it's controlled by the user's
    > browser, not your application. One reliable way to fix it is to change the
    > name of the image each time it's updated.

    I would just like to change this one into "it's controlled by the user's
    buggy browser"
     
    Andrea Desole, Jan 7, 2005
    #3
  4. Juha Laiho Guest

    said:
    >I am having problem with servlet caching. My Servlet keeps displaying
    >previously cached image instead of an updated image. I tried out the
    >following workarounds and was not successful.
    >
    >1. Set the following Response headers
    >
    >res.setDateHeader("Expires", 0);
    >res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate,
    >post-
    >check=0, pre-check=0");
    >res.setHeader("Pragma", "no-cache");


    Below you talk about what you do to some HTML code -- apparently code
    surrounding your image. Are these HTTP headers also for the below HTML?

    Note that the image is served in a separate request from the surrounding
    HTML, and if your problem is with caching the image, then no amount of
    cache-prevention in the surrounding HTML will help -- you have to provide
    the relevant headers (Last-Modified, Expires and Cache-Control) for the
    _image_ HTTP request.


    >2. Set HTML META TAG:

    [...]
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Jan 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. R. Ian Lee

    Prevent Browser Caching for a Page

    R. Ian Lee, Oct 22, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    8,341
    Jacob Yang [MSFT]
    Oct 23, 2003
  2. gu4y
    Replies:
    2
    Views:
    420
    Shiv Kumar
    Jan 20, 2004
  3. Shardul Kulkarni

    Prevent browser from caching

    Shardul Kulkarni, Mar 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    468
    Joerg Jooss
    Mar 19, 2005
  4. Niclas
    Replies:
    1
    Views:
    417
    Niclas
    Jan 4, 2006
  5. circuit_breaker
    Replies:
    2
    Views:
    2,045
    Jack Jia
    Apr 4, 2004
Loading...

Share This Page