Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Workaround for servlet reponse caching

 
Robert Kostes
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The include directive does not need the context path. Just URLs sent from the browser.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic