Solved

Setting the Expires Header in Java Servlet

Posted on 1998-12-17
2
898 Views
Last Modified: 2013-12-25
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() );
0
Comment
Question by:taotree
2 Comments
 
LVL 11

Accepted Solution

by:
mouatts earned 200 total points
ID: 1830204
I can't give you the exact java code as I don't particularly know the object that you are using but the format of the header should appear as follows

Expires: Thu, 01 Dec 1994 16:00:00 GMT

If you look at the page info option under view it will tell you what you are actually outputting.

Any web browser that supports HTPP 1.0 should recognise this. However you can effectively override this value within the browser if the 'Check page' setting is set to every time then the browser will not use the cached version even if prior to its expiry date without first going back to the server to establish is the page is out of date.

Steve
0
 

Author Comment

by:taotree
ID: 1830205
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.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

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

14 Experts available now in Live!

Get 1:1 Help Now