Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpURLConnection - caching - headers

p paul
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code in a servlet:

ObjectOutputStream outToCaller;
response.setHeader("Pragma", "cache");
response.setHeader("Expires", "Fri, 11 Nov 2011 12:19:00 GMT");

outToCaller = new ObjectOutputStream(response.getOutputStream());

I call the above from a console application:

URL urlobj = new URL(servletURL);
HttpURLConnection con = (HttpURLConnection) urlobj.openConnection();
// con.setDoInput(true);
// con.setDoOutput(true);
con.setDefaultUseCaches (true);
con.setRequestProperty ("Content-Type", "application/octet-stream");

tcos is object that has say a timestamp string as follow "The time is 1:00:00"

When I initially make request from servlet, the string "The time is 1:00:00" is returned.
I was attempting to create some type of local/browser cache ability when the page is served. So that a request, say 5 seconds
later, still returns "The time is 1:00:00", not "The time is 1:00:05" . Since I set expires to be in the future, I thought a local cache/browser cache
of the page and object would be created since it is still fresh...But it does not seem to be working...(even through Firefox instead of console app)

Any ideas

tomcat server
live http headers:
HTTP/1.x 200 OK
Server: Apache-Coyote/1.1
Pragma: cache
Cache-Control: public
Expires: Fri, 11 Nov 2011 12:19:00 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Date: Thu, 18 Jun 2009 17:33:20 GMT
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic