views:

67

answers:

3

Hi, i want to map a servlet to URLs end with /. like /user/register/, /user/login/, but not any other resource under that path, not /*.

i tried /*/, but it doesn't work. so please help, is there anyway to make / like end extension mapping.

thanks.

+1  A: 

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
darren
`*/` is an invalid url-pattern as well.
BalusC
/*/ matches exactly /*/. i check the source code of tomcat, but i don't think there is anyway:<
Brodie
A: 

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.

Aadith
+1  A: 

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.

BalusC