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 163257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:32:09+00:00 2026-05-11T11:32:09+00:00

I already read the link checker question posted in SO. If there are more

  • 0

I already read the link checker question posted in SO. If there are more questions of this kind and I missed them, my apologies.

We need to find broken links in a website in a very easy way and scriptable way, so we can document the links that are broken. I found a blog post with some code written in java that will do exactly what I need, and my very basic knowledge let me compile it, but I get errors every time. I thought that maybe someone here might be able to direct me to why the code does not compile.

Here is the code:

import java.net.HttpURLConnection; import java.net.URL; class links {  private static boolean isLive(String link) {     HttpURLConnection urlConnection = null;     try {       URL url = new URL(link);       urlConnection = (HttpURLConnection) url.openConnection();       urlConnection.setRequestMethod('HEAD');       urlConnection.connect();       String redirectLink = urlConnection.getHeaderField('Location');       if (redirectLink != null && !url.equals(redirectLink)) {         return isLive(redirectLink);       } else {         return urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK;       }     } catch (Exception e) {       return false;     } finally {       if (urlConnection != null) {         urlConnection.disconnect();       }     }   }    public static void main(String[] args) {     System.out.println(isLive('http://www.fakelink.net'));   } } 

Thanks to all that reply. I putting the code that compiles here, for future reference.

  • 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. 2026-05-11T11:32:09+00:00Added an answer on May 11, 2026 at 11:32 am

    You need to have the proper packages imported. In this case, you should have the follow at the top of the file:

    import java.net.HttpURLConnection; import java.net.URL; 

    I’m also getting a compiler warning on the following piece of code:

     && !url.equals(redirectLink) 

    It’s trying to equate url (which is a URL) to redirectLink (which is a String). In Java it will automatically compare the string value when this happens and the toString actually gives what you want. To be more precise in the authors code I would change the above code to:

     && !url.toExternalForm().equals(redirectLink) 

    Note: In netbeans, you can simply right click and select the option Fix Imports (or hit Ctrl + Shift + I) and it will try to find the correct packages that you’re currently using and automatically insert the import statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've already read through the similar questions on this topic, but none of them
I've already read this question and this question and this , but none of
Already checked this question: Weak linking UIPopoverBackgroundView and already read: http://www.marco.org/2010/11/22/supporting-older-versions-of-ios-while-using-new-apis#fnref:1 I have a
I know there's quite a few topics on this already, and I've read quite
I hope I get an answer to my question this time, I already posted
I already read many article about this issue in here, SO. I just want
I already read this trick in the cookbook: http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable Now I would like to
Scenario Having already read a post on this on the same site, which didn't
I read an article about digital signature ( link ) and have question as
I've read most of the relevant answers on this topic already, but I can't

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.