java web app - 无法检索不是来自根文件夹的页面

标签 java tomcat jakarta-ee intellij-idea

我使用 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/

相关文章:

java - 获取亚马逊 MWS 节流限制

java - 保存复选框的状态,然后加载它

docker - 容器 docker & Kubernetes apache tomcat 8.5.56 http status 404

java - 传递给 org.jboss.resteasy.spi.metadata.ResourceMethod 的错误参数

java - 如何修复身份始终返回 0 的 HSQL DataSource + TxM

java - Java中的堆栈问题

Java JMX 拒绝与非常奇怪的案例的连接

tomcat - Pivotal CloudFoundry 上的 Nginx/Apache2 httpd 和 Tomcat 7

java - JSTL 在 Java EE 6 中的地位

java - JPA+EJB不是websocket通信中的托管实体