Can I use regex to display Jetty servlets?

I have this one mapping

<servlet-mapping> <servlet-name>service</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping> 

but I also want / Services / master to display on the main servlet.

 <servlet-mapping> <servlet-name>master</servlet-name> <url-pattern>/service/master</url-pattern> </servlet-mapping> 

I believe that there is a conflict here, since call / service / * will immediately call the service servlet. Is there a way to use some kind of exception in servlet mapping, or maybe regexp do what I want to do?

+7
source share
2 answers

Servlet mappings always use the most specific mapping, so the path <context>/service/master will always be mapped to master .

This is the first matching rule from the Servlet 3.0 spec :

  • The container will try to find the exact match of the request path to the servlet path. a successful match selects the servlet.
  • The container will recursively try to match the longest path prefix. This is done by navigating down the directory tree at a time using the command / character as the path separator. The longest match determines the servlet selected.
  • If the last segment of the URL path contains an extension (for example, .jsp), the servlet container will try to match the servlet that processes the extension requests. an extension is defined as part of the last segment after the last. character.
  • If none of the previous three rules leads to a servlet match, the container will try to execute the content corresponding to the resource requested. If the "default" servlet is application-specific, it will be used. Many containers provide an implicit servlet by default for serving content.
+6
source

You can try using Google Guice. com.google.inject.servlet.ServletModule.serveRegex (regular expression String, String ... regexes) allows you to use the regular expression to display.

see here http://code.google.com/p/google-guice/wiki/ServletModule

+1
source

All Articles