Solved

Setting the Expires Header in Java Servlet

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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 …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

622 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