通配符servlet的url-pattern会覆盖文件扩展名模式

9

我希望实现以下目标:

/webapp-context/Page-1               -> Handled by my custom "ContentServlet"
/webapp-context/Another-Page         -> Handled by my custom "ContentServlet"
/webapp-context/Page-with-long-title -> Handled by my custom "ContentServlet"

/webapp-context/_cms/<something>.zul -> Handled by ZK framework
我的最新尝试看起来像这样(web.xml提取):
  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zul</url-pattern>
  </servlet-mapping>

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

很不幸,现在我的内容servlet处理所有请求(我以为更具体的模式优先?)。

如果我将我的内容servlet映射到模式“/webapp-context/content/*”,则不存在冲突,但这不是我想要的。

感谢您的时间。

1个回答

11

我通过这个问题找到了解决方案:Servlet映射URL模式中/和/*的区别

对于我来说,使用'/'而不是'/*'就解决了问题。

<servlet-mapping>
  <servlet-name>myContentServlet</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接