Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

URLConnection.getLastModified()

Posted on 2005-05-15
7
Medium Priority
?
762 Views
Last Modified: 2006-11-18
No matter the site I test, the getLastModified() always returns 0 (unknown).  Does anyone have any ideas why?

URL test = new URL("http://www.hotmail.com");
URLConnection conn = test.openConnection();
System.out.println(conn.getLastModified());

Thanks,
david

0
Comment
Question by:lomidien
  • 4
  • 2
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 14007311
Unless the page is static (relatively rare) it usually will return 0
0
 

Author Comment

by:lomidien
ID: 14007340
well this is bad news indeed.  Let me describe something and perhaps you might have an alternate viewpoint for a different way to go about it.

I'm using the Google api to perform a search....the results are in the neighborhood of 13,000 and I log each url to a database.  This is a news retrieval system for the U.N. and I really don't want to pull down all 13,000 entries each day just to find out if they're different or not...so I was hoping for the last modified date to be useful to me, but it seems that it won't be.

Is there another idea that perhaps is better than what i've got?

Thanks,
David
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 14008506
If the header field Last-Modified in the url does not exists, 0 will be returned. This does not matter whether the page is static or not.

lomidien, you may filter out some URLs by using the following method.

Here is an example:

Calender cal = Calendar.getInstance();
c.add(Calendar.DATE, -1);
URL test = new URL("http://www.hotmail.com");
HttpURLConnection conn = (HttpURLConnection)test.openConnection();

if (conn.getResponseCode() == 304)
   // not modified
else
  // do whatever you want
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:CEHJ
ID: 14008540
>>This does not matter whether the page is static or not

That's true in an absolute way but it's generally more likely not to have it if the response is dynamic

>>Calender cal = Calendar.getInstance();

is not used in your code example btw.

lomidien - if you're implementing this in your program, you should have a sound knowledge of the protocol:

http://www.w3.org/Protocols/rfc2616/rfc2616.html
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 14008624
Sorry, typo:

Calender cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
UR test = new URL("http://www.hotmail.com");
HttpURLConnection conn = (HttpURLConnection)test.openConnection();
conn.setIfModifiedSince(cal.getTimeInMillis());
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14008634
Here's a gentle introduction to these matters:

http://www.edginet.org/techie/website/http.html
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14175575
:-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

580 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