Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:30:47+00:00 2026-05-22T12:30:47+00:00

I am trying to find all the broken links in the webpage using Java.

  • 0

I am trying to find all the broken links in the webpage using Java. Here is the code:

   private static boolean isLive(String link){

    HttpURLConnection urlconn = null;
    int res = -1;
    String msg = null;
    try{

        URL url = new URL(link);
        urlconn = (HttpURLConnection)url.openConnection();
        urlconn.setConnectTimeout(10000);
        urlconn.setRequestMethod("GET");
        urlconn.connect();
        String redirlink = urlconn.getHeaderField("Location");
        System.out.println(urlconn.getHeaderFields());
        if(redirlink != null && !url.toExternalForm().equals(redirlink))
            return isLive(redirlink);
        else
            return urlconn.getResponseCode()==HttpURLConnection.HTTP_OK;

    }catch(Exception e){

      System.out.println(e.getMessage());
      return false;

    }finally{

        if(urlconn != null)
            urlconn.disconnect();

    }


}

public static void main(String[] s){

    String link = "http://www.somefakesite.net";
    System.out.println(isLive(link));

}

Code referred from http://nscraps.com/Java/146-program-code-broken-link-checker.htm.

This code gives HTTP 200 status for all webpages including the broken ones. For example
http://www.somefakesite.net/ gives the following header fields:

{null=[HTTP/1.1 200 OK], Date=[Sun, 15 May 2011 18:51:29 GMT], Transfer-Encoding=[chunked], Keep-Alive=[timeout=4, max=100], Connection=[Keep-Alive], Content-Type=[text/html], Server=[Apache/2.2.15 (Win32) PHP/5.2.12], X-Powered-By=[PHP/5.2.9-1]}

Even though such sites do not exist, how to classify it as a broken link?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:30:48+00:00Added an answer on May 22, 2026 at 12:30 pm

    Maybe the issue is that currently lots of webserver and DNS providers detect those “broken” links and redirect you to their “not found” pages.

    Test it against an URL that you know sends the 404 code (it shows the browser original message).


    EDIT to answer the comment by the author (as it is too long to fit in a comment):
    I do not see an easy answer for your problem, but there are several different types of failures:

    • For DNS failures that are redirected (an URL that cannot be found by the DNS, and you get redirected to another page). All redirections (if you are redirected) will likely go to the same page (provided by your ISP/DNS provider), you can check for that. Of course, if you try with another ISP/DNS provider the page might be different. If you are not being redirected then you will get a connection error.
    • For a server with valid DNSs but not working (for example, google.com goes down), there should be a connection error.
    • For a resource (“page”) missing in a server, it is more difficult. 404 means it is broken, but if the server does not send it there is little more to do. A redirection might be useful to flag a link as dubious, but it should be manually checked later because it is not only used for capturing missing links (for example, http://www.google.com redirects me http://www.google.es)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java, I'm trying to log into an FTP server and find all the
using jQuery i am trying to find out all the URLS that user has
I am trying to find all the .c files in a directory using Python.
I'm trying to find all long filenames in a directory using: find . -regex
Hi i'm trying to find all occurences of '<?' in my php code. I
I'm trying to find about ALL the possible options that I can set in
I'm trying to use XPath to find all elements that have an element in
I'm trying to use VDMEnumProcessWOW to find all 16 bit host processes on Vista.
In Ruby, I'm trying to do the following. def self.stats(since) return Events.find(:all, :select =>
Because regular expressions scare me, I'm trying to find a way to remove all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.