Is there a way to map a Java Servlet to */?
I want to map a开发者_如何转开发 Servlet
to URLs ending in /
, like /user/register/
, /user/login/
, but not any other resource under that path, not /*
.
I tried /*/
, but it doesn't work.
I may be wrong, but I'm not sure this is possible. the wildcard * is only used at the end of url patterns:
# this is a valid pattern to match anything after root:
*/
# this does not match anything because nothing can come after *
/*/
# this would match anything after the . that was htm
*.htm
Map a Filter
on /*
and let it determine whether the request needs to be passed through the servlet or not.
if (request.getRequestURI().endsWith("/")) {
request.getRequestDispatcher("/servleturl").forward(request, response);
} else {
chain.doFilter(request, response);
}
This way you can just map the desired Servlet
on /servleturl
.
welcome-file-list is what you are looking for. under the welcome-file-list you can specify a list of welcome-files (each under its own welcome-file tag). When the request URL ends with /, the application would look for the presence of one of those files you have mentioned in welcome-file-list (in the order you have specified there i guess) under the folder pointed to by the URL, and serve that resource.
精彩评论