java – 是否可以为Jetty的servlet映射使用正则表达式?

前端之家收集整理的这篇文章主要介绍了java – 是否可以为Jetty的servlet映射使用正则表达式?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个映射
<servlet-mapping>
<servlet-name>service</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>

但我也想要
/服务/主
映射到主servlet.

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

我相信这里存在冲突,因为调用/ service / *会立即触发服务servlet.有没有办法让我在servlet映射中使用某种排除,或者可以使用regexp来做我想做的事情?

解决方法

Servlet映射始终​​使用最具体的匹配,因此路径< context> / service / master将始终映射到master.

这是Servlet 3.0 spec的第一个映射规则

  1. 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.
  2. 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.
  3. 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.
  4. 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.
原文链接:https://www.f2er.com/java/129906.html

猜你在找的Java相关文章