• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to stop caching problem in jsp

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using glassfish as server and jsp for sqlserver connectivity .. i ve retieved images from DB to a specific location and try to update it in the page but oly the first time the image loads later the same images get loaded... TEll me how to use Etag and last modified to avoid caching...
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kavinkumar kumar wrote:I am using glassfish as server and jsp for sqlserver connectivity .. i ve retieved images from DB to a specific location and try to update it in the page but oly the first time the image loads later the same images get loaded... TEll me how to use Etag and last modified to avoidcaching...



Can you elaborate the below,

"i ve retieved images from DB to a specific location"


Are you retrieving the image from DATABASE and placing in a physical repository ???
 
kavinkumar Rajendran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guru Vijay wrote:

Are you retrieving the image from DATABASE and placing in a physical repository ???



I ve retrieved the images from db already and saved them in systems HD , when i ry to upload them onto jsp page oly 1st time the image gets loaded nxt time instead of getting new image from HD it get old image from server cache.. now i want to know how to bypass server cache and to upload image on jsp page tat can be changed dyanmicallly
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and I remember Bear always says here why filter is good!(one of the reason though) :)
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked through the JspFaq and ServletsFaq for information on cache control?
 
kavinkumar Rajendran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried cache control solutions but none worked.. For me my server s caching the script and img files..any Solution guys..
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kavinkumar Rajendran wrote:I tried cache control solutions but none worked.. For me my server s caching the script and img files..any Solution guys..



Hi,

The solution is as follows:

1. Not the jsp is cached - *.jsp url is never cached but the images. The images are the object of separate http requests

2. How you do it

instead of

you put


And generate instead of randomstuffhere some random string. The best for me worked with a java class called RandomGuid which is freely available on the internet.

This used to be a very good approach for the old mobile browser programming back in the days when phones were dumb and were caching everything. Be careful though as your browser sandbox will fill with various images - not that it would be a big issue.

D
 
kavinkumar Rajendran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Val wrote:

kavinkumar Rajendran wrote:I tried cache control solutions but none worked.. For me my server s caching the script and img files..any Solution guys..



Hi,

The solution is as follows:

1. Not the jsp is cached - *.jsp url is never cached but the images. The images are the object of separate http requests

2. How you do it

instead of

you put


And generate instead of randomstuffhere some random string. The best for me worked with a java class called RandomGuid which is freely available on the internet.

This used to be a very good approach for the old mobile browser programming back in the days when phones were dumb and were caching everything. Be careful though as your browser sandbox will fill with various images - not that it would be a big issue.

D




ll try that Daniel ...thanks...
 
kavinkumar Rajendran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ll this work ??

<img src="<%=adress%>">

where
String adress="name.jpg?id=123abc";
 
Daniel Val
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kavinkumar Rajendran wrote:ll this work ??

<img src="<%=adress%>">

where
String adress="name.jpg?id=123abc";


Please give it a try - should be fine, but where do you take the address from?

Or write a tag that would merely render some random stuff and then use it there. You might need it elsewhere as well...

Personally I avoid at all cost Java code in jsp pages;

Daniel
 
kavinkumar Rajendran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UUID idone = UUID.randomUUID();
<img src="1.jpg?id=<%=idone%>" id="i1">

I tried this and also kept entire "1.jpg?id=randvalue" in a string and then executed the jsp the image din change at all...

can you explain the other solution you provided Daniel.. Thanks in advance
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel is very correctly suggesting that you no longer use Java code and Java Scriptlets in JSP pages. That is a practice that has been discredited for 10 years now. Do you not think that you should start using more modern approaches such as the JSTL and EL?

A custom tag that generates a random value (by whatever means) would be one way to implement this. I think that an EL function would be preferable as it is a bit more versatile as it can be used in contexts in which tags are not allowed.

Personally, I'd avoid polluting the page with such implementation details at all and implement a filter that applies the cache control headers to the image requests.
 
kavinkumar Rajendran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dono how to use JSTL or EL .. I Actually finished my entire project the oly problem s that i get the same images always..

If there s a way to break cache in JSTL or EL let me know.. I open to options guys...


And one more thing Guys ..Etags and lastmodified tags can solve the cache problem it seems..so can anyone explain me how to use them...

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kavinkumar Rajendran wrote:I dono how to use JSTL or EL


And this is an excuse not to learn them?

If you are a novice to JSP, why are you wasting time using technology that's 10 years old? Learn the correct way of coding JSPs now.

I also recommend that novices to JSP read the following articles:
  • The Secret Life of JSPs
  • The Front Man


  • .. I Actually finished my entire project the oly problem s that i get the same images always..


    "oly"? I have no idea what you are trying to say here.

    If there s a way to break cache in JSTL or EL let me know.. I open to options guys...


    Before posting in the forums you should have checked the FAQs. Have you looked through the JspFaq and ServletsFaq for information on cache control?
     
    reply
      Bookmark Topic Watch Topic
    • New Topic