UrlValidator不适用于localhost

Lit*_*ird 10 java url-validation

我正面临一个问题,我在我的代码中使用了UrlValidator.

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
Run Code Online (Sandbox Code Playgroud)

如果我正在传递url,我将收到IllegalArgumentException

 [2]: https://www.google.co.in/
Run Code Online (Sandbox Code Playgroud)

它的工作正常.如何使此代码适用于localhost:8080

Ale*_*reg 24

如果您查看文档,您将获得有关如何接受本地URL的提示

例如

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");
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

它会输出

Valid URL