wood burning stoves 2.0*
The moose likes Servlets and the fly likes Workaround for servlet reponse caching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Workaround for servlet reponse caching" Watch "Workaround for servlet reponse caching" New topic
Author

Workaround for servlet reponse caching

Robert Kostes
Greenhorn

Joined: Feb 04, 2013
Posts: 7
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Robert Kostes
Greenhorn

Joined: Feb 04, 2013
Posts: 7
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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

Joined: Feb 04, 2013
Posts: 7
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

The include directive does not need the context path. Just URLs sent from the browser.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Workaround for servlet reponse caching