简体   繁体   English

Servlet 3 Web片段-不从META-INF中的文件夹提供静态内容

[英]Servlet 3 web fragments - not serving static content from folder in META-INF

I am having trouble deciding if I don't correctly understand the Servlet 3.0 spec or if there is a bug in Tomcat. 我无法确定我是否不正确理解Servlet 3.0规范,或者Tomcat中是否有错误。

Here is my situation. 这是我的情况。 I have a web application that includes a jar project. 我有一个包含jar项目的Web应用程序。 The web application defines a set of REST endpoints using Jersey 2.9. Web应用程序使用Jersey 2.9定义了一组REST端点。 The jar project also defines REST endpoints (also using Jersey 2.9) and has static content in the META-INF/resource directory. jar项目还定义了REST端点(也使用Jersey 2.9),并且在META-INF / resource目录中具有静态内容。 The structure of the META-INF directory in the jar looks like this: jar中的META-INF目录的结构如下所示:

META-INF
  |- resources
    |- test.html
    |- testfolder
      |- test2.html

I run this on Tomcat 8.5.16. 我在Tomcat 8.5.16上运行它。 When I'm running this I get the following results: 运行此程序时,将得到以下结果:

  1. WAR REST endpoints: successful WAR REST端点:成功
  2. JAR REST endpoints: successful JAR REST端点:成功
  3. /test.html: successful /test.html:成功
  4. /testfolder/test2.html - FAILED with a 404 /testfolder/test2.html-失败并显示404

The WAR project has no static content, so I no there are no conflicts occurring. WAR项目没有静态内容,因此没有冲突发生。 I have checked the JAR file inside the WAR and it contains the structure shown above. 我已经检查了WAR内的JAR文件,其中包含上面显示的结构。

Any ideas on why the top level html file is served, but not the one in the folder? 为什么提供顶级html文件而不是文件夹中的任何想法?

Put your resources in a top-level folder in your WAR named /static. 将资源放在WAR中名为/ static的顶级文件夹中。 Tomcat will then serve them. 然后,Tomcat将为他们提供服务。 There are other folder names that do the same thing. 还有其他文件夹名称也可以执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM