• Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpURLConnection - caching - headers  RSS feed

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

ObjectOutputStream outToCaller;
response.setContentType("application/octet-stream");
response.setHeader("Pragma", "cache");
response.setHeader("Cache-Control","public");
response.setHeader("Expires", "Fri, 11 Nov 2011 12:19:00 GMT");

try
{
outToCaller = new ObjectOutputStream(response.getOutputStream());
outToCaller.writeObject(tcos);
outToCaller.flush();


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.setUseCaches(true);
con.setDefaultUseCaches (true);
con.setRequestProperty ("Content-Type", "application/octet-stream");
con.setAllowUserInteraction(false);
con.setRequestMethod("GET");

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

Stats
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!