0

Within a struts 2 action, how can I determine if a given URL (assumed to be served by the current server) would result in a 404 "not found" result.

Background: For the search box on our site, we use google custom search. Because google doesn't index frequently, we sometimes run into cases where google will return a URL in a search result that now results in a 404 "not found" condition. What I'd like to do is eliminate those results from what I display to the user, without having to reinvent a bunch of parsing, etc, type of logic.

Approaches I've considered:

1) Use Ajax on the client to do a HEAD on each result link and hide/remove those that return a 404. This could be less than perfect for the user as some requests might take a while to process, so link results would visibly disappear, which could be disconcerting.

2) Similar to 1), but do this from the server - essentially making a recursive HEAD call to the server for each link before I include it in the search results.

What I'd really like is something like 2) but without the network overhead.

Mitch
  • 989
  • 1
  • 9
  • 25
  • A `HEAD` request should not take any time to process. Without poking around in the innards of the Struts dispatcher I don't see another way to do this. – Boris the Spider Sep 18 '14 at 16:25
  • possible duplicate of [Preferred Java way to ping a HTTP Url for availability](http://stackoverflow.com/questions/3584210/preferred-java-way-to-ping-a-http-url-for-availability) – Andrea Ligios Sep 18 '14 at 16:32

0 Answers0