Generating Expires Header for 1 hour from now

Can someone please give me the exact Java code to generate the expires header in a Java servlet that would make it expire 1 hour from now, and are there any problems with browsers supporting this?

I ask for the exact code because I have code that already should do it, I thought, but it doesn't work. Sometimes netscape (perhaps others) will continually re-request to the servlet again and again when I use the code below:

   dateNow.setTime( dateNow.getTime() + (1000*60*60) );
   res.setHeader( "Expires", dateNow.toGMTString() );

Does anyone know why that happens? What am I doing wrong?
taotreeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Dracula112698Connect With a Mentor Commented:
toGMTString is deprecated in 1.1.
I think that's the problem.

Dracula
0
 
heyhey_Commented:
maybe this behaviour depends on some browser settings like
"ingnore cache always" / "rerequest always" ???

maybe you should post this question at the browser forum (you can simply post a pointer to this question saying that it is worth 200 points)

hope this helps
  heyhey


0
 
nbellCommented:
Date dateNow=new Date();//default constructor initializes
                        //to current time
res.setDateHeader("Date",dateNow.getTime());
res.setHeader( "Expires", dateNow.getTime()+(1000*60*60));

need more code? let me know

0
 
nbellCommented:
oops last line should read:

res.setHeader( "Expires", Long.toString(dateNow.getTime()+(1000*60*60)));

0
All Courses

From novice to tech pro — start learning today.