Link to home
Start Free TrialLog in
Avatar of taotree
taotree

asked on

Setting the Expires Header in Java Servlet

Can someone please give me the exact Java code to place the expires header in a Java servlet that would make it expire exactly 1 hour from now. Also, how compatible is this header with browsers?

I ask for the exact code because I have code that already does 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() );
ASKER CERTIFIED SOLUTION
Avatar of mouatts
mouatts

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of taotree
taotree

ASKER

I need the Java code because I thought the toGMTString would do it, but it's not working. My concern isn't that they will reload early, but rather they absolutely must not access the cached version after an hour.

In other words, what is an easy standard way in Java to generate that date/time format for 1 hour from the current time?

Perhaps I should post this in the Java category.