• 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

Workaround for servlet reponse caching

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a page divided into two sections. One is a list of names of object type X and the other is a form to display the detail of a selected instance.

I have been suffering the same problem as a number of other posts. On the second look at a given instance, the get() never calls the servlet to retrieve possibly updated data.

I have tried all of the recommendations to stop this with no luck.

Here is what I do:


The random number makes the cache mechanism think it is a new request. I have no idea what is doing the caching, but this seems to "disable" it. No gaurentee that I won't get a duplicate random number at some point though. I will keep listening for a better solution.

Robert
 
Sheriff
Posts: 67747
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
Firstly, never use the "../" notation in a web application. That's a fragile recipe for disaster. Always use server-relative URLs that start with the context path.

Secondly, are you setting the cache control headers on your response? If not, see the ServletsFaq for details.
 
Robert Kostes
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tip.

Yes, setting all the headers (got from other post here) with no luck. Also set cachingAllowed="false" in context.xml. No effect.

My pages are in various subdirectories except for the servlets. I have tried using /dir/page and /servlet but it never works. I have to use ../servlet or ../dir/page.
 
Bear Bibeault
Sheriff
Posts: 67747
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
No, you don't have to do it that way. It's wrong and you shouldn't do it that way. It may, in fact, be contributing to your problem. I did not say to use /servlets or anything like that. I said to use server-relative addressing that starts with the context path.

See this FAQ entry for details.
 
Robert Kostes
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Read the FAQ and made changes. That did fix one other problem I was having but not this one. I removed the random number and added the header information back in:



But the old response was still held on to. Commented these out and put the random number back in and it works fine.

One other thing about context path. I tried using the two formats in the FAQ in the <%@ include file="" directive and the Eclipse IDE didn't like any of them. I use /dir/file for all of my includes and they seem to work. Am I just getting the syntax wrong? I have so many different syntaxes in my head I would not be surprised if I wasn't getting it right.
 
Bear Bibeault
Sheriff
Posts: 67747
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
The include directive does not need the context path. Just URLs sent from the browser.
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic