Solved

Generating Expires Header for 1 hour from now

Posted on 1998-12-18
4
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 …
This video teaches viewers about errors in exception handling.
Suggested Courses

737 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