I have this one mapping
<servlet-mapping>
<servlet-name>service</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
but i also want /service/master to map to master servlet.
<servlet-mapping>
<servlet-name>master</servlet-name>
<url-pattern>/service/master</url-pattern>
</servlet-mapping>
I believe there is a conflict here since calling /service/* will trigger service servlet right away. Is there a way for me to use some kind of exclusion in servlet-mapping or may be regexp to do what I want to do?
Servlet mappings always use the most specific match, so the path <context>/service/master
will always map to master
.
This is the 1st rule of mappings from the Servlet 3.0 spec:
- The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
- The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the ’/’ character as a path separator. The longest match determines the servlet selected.
- If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last ’.’ character.
- If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a "default" servlet is defined for the application, it will be used. Many containers provide an implicit default servlet for serving content.
You can try using Google Guice. com.google.inject.servlet.ServletModule.serveRegex(String regex, String... regexes) will let you use regex in mapping.
see here http://code.google.com/p/google-guice/wiki/ServletModule
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With