What is the difference between / and /* in web.xml ?
for the dispatcher servlet / is used and i guess this means all the requests.In that case what does url-pattern "/*" means ?
What is the difference between / and /* in web.xml ?
for the dispatcher servlet / is used and i guess this means all the requests.In that case what does url-pattern "/*" means ?
/*
means "all requests", whereas /
means "all requests not handled by other servlets".
In particular, a common source of confusion is that /*
overrides mappings of built-in servlets, such as JSP servlet. It means that if you map DispatcherServlet
to /*
, you won't be able to use JSP-based views, because requests to render these views will be handler by DispatcherServlet
itself rather than by JSP servlet that actually renders JSP pages.
That's why DispatcherServlet
that should handle all requests is usually mapped to /
.
from SRV.11.2 Specification of Mappings
In the web application deployment descriptor, the following syntax is used to define mappings:
- A string beginning with a ‘/’ character and ending with a ‘/*’ postfix is used for path mapping.
- A string beginning with a ‘*.’ prefix is used as an extension mapping.
- A string containing only the ’/’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
- All other strings are used for exact matches only.
The pattern /*
will force everything through your servlet. The pattern /
will make your servlet the default servlet for the app, meaning it will pick up every pattern that doesn't have another exact match