Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UrlValidator is not working for localhost

I'm facing an issue that i'm using UrlValidator in my code.

UrlValidator urlValidator = UrlValidator.getInstance();
    if(urlValidator.isValid(url)) {
        throw new IllegalArgumentException( url + "not valid");
    }
 where url i'm passing is 

 [1]: http://localhost:8080/myapp/Education.html

.I'm getting IllegalArgumentException n if i'm passing url i.e

 [2]: https://www.google.co.in/

its working fine.How to make this code working for localhost:8080

like image 274
Little bird Avatar asked Aug 08 '14 09:08

Little bird


1 Answers

if you take a look at the documentation you'll have a hint on how to accept local urls

For example

public class Validator {
    public static void main(String[] args) {
        UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
        if (urlValidator.isValid("http://localhost/page.htm")) {
            System.out.println("Valid URL");
        }
        else {
            System.out.println("Invalid URL");
        }

    }

}

it will output

Valid URL

like image 185
AlexGreg Avatar answered Nov 01 '22 00:11

AlexGreg