Solved

Setting the Expires Header in Java Servlet

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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)

746 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

10 Experts available now in Live!

Get 1:1 Help Now