Validating URI, below redirect. Web App : Servlets Java
I have URL entered by users.
User can enter URI. [relat开发者_如何学Cive URI]
How can I validate that relative URI ?
EX: For absolute URI https://stackoverflow.com/questions/ask.
User can enter "questions/ask".
Is there any ways read web.xml to validate uri.[Java web app]
if you can verify whether the address actually exists, you can use:
HttpURLConnection connection = (HttpURLConnection) new URL(host + relativePart).openConnection(); int status = connection.getResponseCode();
and see whether status 200 will be returned.
- if you want to check if the URI is well formed according to RFC 2396 -
new URI(uri)
精彩评论