简体   繁体   English

SpringMVC评估URL链接

[英]SpringMVC valadation URL link

How can I do URL validation from my site? 如何从我的网站进行URL验证? For example, if a user accesses one URL link like "mysite.com", he proceeds to the web page. 例如,如果用户访问一个URL链接,例如“ mysite.com”,则他将转到该网页。 However, if he try another URL like "mysite.com/what", I what to show an error message, and tell him this like is not valid. 但是,如果他尝试使用其他网址,例如“ mysite.com/what”,我将显示一条错误消息,并告诉他这样的内容无效。

I've tried this method, but it don't work and UrlValidator is deprecated: http://www.mkyong.com/java/how-to-validate-url-in-java/ 我已经尝试过这种方法,但是它不起作用, 并且不赞成使用UrlValidatorhttp//www.mkyong.com/java/how-to-validate-url-in-java/

Any ideas? 有任何想法吗?

There are several options to achieve what you want, each one depends on how "deep" you want to dig and validate your URL: a URL may be syntactically correct but the (sub)domain does not exist. 有几种方法可以实现所需的目的,每个选项都取决于您要挖掘和验证URL的“深度”程度:URL在语法上可能是正确的,但是(子)域不存在。 You may need this (but you didn't tell us whether you are using Spring Framework) or you can build your own UrlValidator using the Common Apache version and Google Guava together, as we did for instance for email addresses. 您可能需要这个 (但您是否使用Spring,你没有告诉我们),也可以使用建立自己的UrlValidator 常见的Apache版本, 谷歌番石榴在一起,因为我们没有例如电子邮件地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM