我使用 Intellij-idea IDE 和 tomcat。我试图检索里面的页面 我的 web-inf 中的文件夹并出现 HTTP 错误 404。但是我只能检索根文件夹中的页面。
怎么办?
谢谢。
最佳答案
来自servlet spec , section 10.5 Directory structure (我强调):
A special directory exists within the application hierarchy named “WEB-INF”. This directory contains all things related to the application that aren’t in the document root of the application. Most of the WEB-INF node is not part of the public document tree of the application. Except for static resources and JSPs packaged in the META- INF/resources of a JAR file that resides in the WEB-INF/lib directory, no other files contained in the WEB-INF directory may be served directly to a client by the container. However, the contents of the WEB-INF directory are visible to servlet code using the getResource and getResourceAsStream method calls on the ServletContext, and may be exposed using the RequestDispatcher calls...
因此,您的体验是“设计使然”的。如果您需要通过 HTTP 请求它们,请将您的资源放在别处。
关于java web app - 无法检索不是来自根文件夹的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25867187/