Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Generating Expires Header for 1 hour from now

Posted on 1998-12-18
4
Medium Priority
?
255 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

618 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