Java 来自 WEB-INF 文件夹的 web.xml 欢迎文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16180090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:38:36  来源:igfitidea点击:

web.xml welcome file from WEB-INF folder

javatomcatservletsweb.xml

提问by Arturas M

I get the resquested resource is not available error while trying to load a welcome file from the WEB-INF folder, in my web.xml it looks like this:

尝试从 WEB-INF 文件夹加载欢迎文件时,出现 resquested resource is not available 错误,在我的 web.xml 中,它看起来像这样:

<welcome-file-list>
    <welcome-file>WEB-INF/html/index.html</welcome-file>
</welcome-file-list>

In other words, the html files are located in the WEB-INF directory in the folder named "html"...

换句话说,html文件位于名为“html”的文件夹中的WEB-INF目录中......

So how do I do this correctly? It's so complex all this paths thing, I mean is there some kind of paths guide or anything? Because I just can't develop because I get stuck at these things when something can't be found because the path i write is interpreted differently than I expect it to...

那么我该如何正确地做到这一点呢?所有这些路径都如此复杂,我的意思是有某种路径指南或其他什么东西吗?因为我无法开发,因为当找不到某些东西时,我会陷入这些事情中,因为我写的路径的解释与我预期的不同......

采纳答案by Alfabravo

You cannot access files under WEB-INF folder directly. Container will look for classes in WEB-INF/classes and jsp files under WEB-INF can be included by other JSP, but any browser requesting resources down there will get a 404 response.

您不能直接访问 WEB-INF 文件夹下的文件。容器会在 WEB-INF/classes 中寻找类,WEB-INF 下的 jsp 文件可以被其他 JSP 包含,但是任何浏览器请求资源在那里都会得到 404 响应。

EDIT: About your doubt below, if you have a standard Java EE webapp, below the root folder you should have:

编辑:关于你的疑问,如果你有一个标准的 Java EE webapp,在你应该有的根文件夹下面:

/-
 |
 |-META-INF/
 |-WEB-INF/
 |-custom1/
 |-custom2/

The first two are mandatory, but you can create extra subfolders (e.g. customX). Personally I create a custom folder "resources" to allocate there html, css and js files (in separate subfolders). If I have special JSP files which should not be accesed directly (only thru includes), I place them inside WEB-INF/.

前两个是强制性的,但您可以创建额外的子文件夹(例如 customX)。我个人创建了一个自定义文件夹“资源”来分配 html、css 和 js 文件(在单独的子文件夹中)。如果我有不应该直接访问的特殊 JSP 文件(仅通过包含),我会将它们放在 WEB-INF/ 中。

回答by Santanor

i'm gonna tell you how i have the wellcome file, i have it like this

我要告诉你我是怎么得到 Wellcome 文件的,我是这样的

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

and the "index" is in the "web" folder, maybe you should set the wellcome file with just the name.

并且“索引”位于“web”文件夹中,也许您应该仅使用名称设置wellcome 文件。

I hope this one helps you ;)

我希望这对你有帮助;)

回答by Mike Tunnicliffe

Files in the WEB-INF directory are not directly available for access.

WEB-INF 目录中的文件不能直接访问。

See URL:

网址

Place private files in the WEB-INF directory, under the root directory. All files under WEB-INF are private, and are not served to a client.

将私有文件放在根目录下的 WEB-INF 目录中。WEB-INF 下的所有文件都是私有的,不提供给客户端。

回答by Sandeep Bhardwaj

WEB-INF folder is not accessible directly to web browser since this folder is meant for keeping files which are internal to application i.e. classes and configuration files etc. welcome page is something that should not contain any specific or private information, so can be kept in parallel to WEB-INF folder. All static html files can be placed at same hierarchy as of welcome file. To distinguish better, we can create sub folders.

WEB-INF 文件夹不能被 Web 浏览器直接访问,因为该文件夹用于保存应用程序内部的文件,即类和配置文件等。欢迎页面不应包含任何特定或私人信息,因此可以保存在与 WEB-INF 文件夹平行。所有静态 html 文件都可以放置在与欢迎文件相同的层次结构中。为了更好的区分,我们可以创建子文件夹。