Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Link Checking

 
Jeremy Quartey
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone give me a few tips on what facilities in Java could I use to develop a simple Applet system which checks whether a series of URL links have been changed since the system was last accessed by the user who provided the links. The system will eventually also provide facilities for adding, deleting and modifying links.
Regards
 
Zakaria Haque
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An unsigned applet can only access the server from where it was downloaded. So either you have to use signed applets(which is far from being simple), or you can have a server running on codebase do the checking for you.
Basically what you have to do is send a HEAD (GET can be unnecessarily expensive) request to the HTTP server and check the Last-Modified header of the response with the last access time of your application. Here is some untested code to give you a start,
long lastAccessedByUser = you should have it stored somewhere
long lastModified=0;
URL url = new URL("http://...");
HttpURLConnection con = (HttpURLConnection )url.openConnection();
con.setRequestMethod("HEAD");
.. any other set operation on teh connection object
con.connect();
int responseCode = con.getResponseCode();
if( responseCode >= 200 && responseCode < 300 ) {
lastModified = Integer.parseInt(con.getHeaderField("Last-Modified"));
}else {
... throw some exception
}
if(lastModified > lastAccessedByUser) {
... the link has changed ...
}

Hope it helps.
[ March 27, 2002: Message edited by: zakaria haque ]
[ March 27, 2002: Message edited by: zakaria haque ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic