简体   繁体   中英

SpringMVC valadation URL link

How can I do URL validation from my site? For example, if a user accesses one URL link like "mysite.com", he proceeds to the web page. 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.

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/

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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