如何在Java中检查有效的URL? [英] How to check for a valid URL in Java?
本文介绍了如何在Java中检查有效的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
检查URL在Java中是否有效的最佳方法是什么?
What is the best way to check if a URL is valid in Java?
如果试图调用new URL(urlString)
并捕获到MalformedURLException
,但对于以http://
开头的任何内容似乎都感到满意.
If tried to call new URL(urlString)
and catch a MalformedURLException
, but it seems to be happy with anything that begins with http://
.
我不关心建立连接,只是有效性.有办法吗? Hibernate Validator中的注释?我应该使用正则表达式吗?
I'm not concerned about establishing a connection, just validity. Is there a method for this? An annotation in Hibernate Validator? Should I use a regex?
编辑:接受的URL的一些示例为http://***
和http://my favorite site!
.
Some examples of accepted URLs are http://***
and http://my favorite site!
.
推荐答案
查看全文