Considering a Servlet (called EmailVerification
) mapped to /ev/*
:
Will the URL
http://example.com/ev/ce52320570
trigger theEmailVerification
servlet ?
Yes. In Servlet versions 2.5 and 3.0 (maybe earlier), it'll get the subpath if you map it with *
, like /ev/*
, as you did.
How can I get this
ce52320570
part of the URLhttp://example.com/ev/ce52320570
?
request.getRequestURI()
will get you the requested URL as aString
, like/ev/ce52320570
.request.getPathInfo()
gets you (if exists) everything after/ev/
.- So in a request to
/ev/123
,getPathInfo()
would give you/123
. The same way, a request to/ev/some/other
,getPathInfo()
would give you/some/other
.
- So in a request to
request.getQueryString()
should be used if you need the query parameters part of the URL.- Keep in mind both
getRequestURI()
andgetPathInfo()
give you only the path requested. If you need to obtain the query parameters, that is, those after the?
, like/ev/something?query1=value1&other=123
, onlyrequest.getQueryString()
would return thequery1=value1&other=123
part.
- Keep in mind both
request.getParameter(parameterName)
if you need the value of a specific query parameter.- Resort to
.getParameterValues()
if it is a multivalued parameter
- Resort to
More examples of the URL parts in the request here.