Solved

Generating Expires Header for 1 hour from now

Posted on 1998-12-18
4
247 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 48
sumHeights2  challenge 7 76
changePi Challenge 15 75
Cipher Configuration on Apache HTTPD 4 17
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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

12 Experts available now in Live!

Get 1:1 Help Now