Solved

Generating Expires Header for 1 hour from now

Posted on 1998-12-18
4
248 Views
Last Modified: 2013-11-24
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?
0
Comment
Question by:taotree
  • 2
4 Comments
 

Accepted Solution

by:
Dracula112698 earned 200 total points
ID: 1229713
toGMTString is deprecated in 1.1.
I think that's the problem.

Dracula
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229714
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
 

Expert Comment

by:nbell
ID: 1229715
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
 

Expert Comment

by:nbell
ID: 1229716
oops last line should read:

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

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now