Package Com.inspur.linkcheck;import Java.io.ioexception;import Java.net.httpurlconnection;import Java.net.URL; public class Linkcheck {public static void main (string[] args) {System.out.println (Checkurl ("HTTP/ 202.110.193.23:8000/zrqd/themes/default/skins/images/bg_body_footer.png "));} public static Boolean Checkurl (String url_s) {try {URL url = new URL (url_s); HttpURLConnection conn = (httpurlconnection) url.openconnection ();/** * public int Getresponsecode () throws IOException from The HTTP response message gets the status code. * For example, for the following status lines: http/1.0-OK http/1.0 401 Unauthorized will return 200 * and 401 respectively. Returns 1 if no code is recognized from the response (that is, the response is not a valid HTTP). * * Returns the HTTP status code or-1 */int state = Conn.getresponsecode (); System.out.println (state), if (state = =) {return true;} else {System.out.println ("Invalid:" + url_s); return false;}} catch (IOException e) {return false;}}}
Detecting Web page address validity Java code