Solved

Setting the Expires Header in Java Servlet

Posted on 1998-12-17
2
906 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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…

821 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