Java 无法在 netbeans 7.0.1 中找到 web.xml

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19317410/
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-12 16:02:12  来源:igfitidea点击:

Unable to find web.xml in netbeans 7.0.1

javajakarta-eeservletsweb.xmldeployment-descriptor

提问by Saumyaraj

I want to upload a file to a server, for which I am writing a servlet program.The location of the directory where the document would be uploaded should be fetched from a parameter in web.xml. I have not use web.xml before and only know that it makes entries for each servlet. I am not able to see this file in my web application project that i am making in netbeans. Please help me with this. Thank you.

我想将文件上传到服务器,我正在为其编写 servlet 程序。应该从 web.xml 中的参数获取上传文档的目录的位置。我以前没有使用过 web.xml,只知道它为每个 servlet 生成条目。我无法在我在 netbeans 中制作的 Web 应用程序项目中看到此文件。请帮我解决一下这个。谢谢你。

采纳答案by Saumyaraj

It should be located in YOURPROJECT\web\WEB-INFfolder, so the full path will be: YOURPROJECT\web\WEB-INF\web.xml

它应该位于YOURPROJECT\web\WEB-INF文件夹中,因此完整路径为:YOURPROJECT\web\WEB-INF\web.xml



EDIT (Aug 21, 2015)

编辑(2015 年 8 月 21 日)

Got a downvote with a comment from duffymo, that my answer is not correct.

得到了来自duffymo 的反对票,我的回答不正确。

comment

评论

And I decided to illustrate my answer with step-by-step pictures to avoid any misunderstanding.

我决定用逐步的图片来说明我的答案,以避免任何误解。

I am going to illustrate Netbeans behaviour in Linux (Ubuntu) and Windows (Windows 7) operating systems.

我将说明 Linux (Ubuntu) 和 Windows (Windows 7) 操作系统中的 Netbeans 行为。

Linux:

Linux:

  1. Let's create a simple Java Web project with default settings.
  1. 让我们使用默认设置创建一个简单的 Java Web 项目。

simple web project on linux system

linux系统上的简单web项目

  1. We're going to the project folder to inspect the contents of this folder:
  1. 我们将转到项目文件夹以检查此文件夹的内容:

web project folder on linux system

linux系统上的web项目文件夹

note, that webfolder is there.

请注意,该web文件夹在那里。

  1. Navigating further:
  1. 进一步导航:

contents of web folder on linux system

linux系统上web文件夹的内容

web.xml file location on linux system, file is not created yet

web.xml 文件在 linux 系统上的位置,文件尚未创建

You can create a web.xml file in this folder manuallyor do it using Netbeans via project context menu "New -> Create -> Other":

可以在此文件夹中手动创建 web.xml 文件,也可以通过项目上下文菜单“新建 -> 创建 -> 其他”使用 Netbeans 执行此操作

creating web.xml on linux system in netbeans #1

在 linux 系统上用 netbeans #1 创建 web.xml

creating web.xml on linux system in netbeans #2

在 linux 系统上用 netbeans #2 创建 web.xml

Now, we're navigating YOURPROJECT\web\WEB-INF\folder to see, that web.xmlis there:

现在,我们正在浏览YOURPROJECT\web\WEB-INF\文件夹以查看,就web.xml在那里:

created web.xml file

创建的 web.xml 文件

The same rules are correct for windows operating system, check the pictures below:

相同的规则适用于 windows 操作系统,请查看下图:

web-application project folder on windows

Windows 上的 Web 应用程序项目文件夹

contents of web-application folder on windows

Windows 上的 web-application 文件夹的内容

You can create web.xml here:

您可以在此处创建 web.xml:

web.xml file location on windows

Windows 上的 web.xml 文件位置

or use Netbeans, as I described above.

或使用 Netbeans,如上所述。

回答by Masudul

web.xmlis optional in Java EE 6. So, by default it is not loaded in Netbeans. You need to manually load web.xmlfrom Netbeans.

web.xmlJava EE 6. 因此,默认情况下它不会加载到Netbeans. 您需要web.xml从 Netbeans手动加载。

回答by user987339

You could use context-parameters in your web.xml

您可以在 web.xml 中使用上下文参数

In you normal java class you read this this static fields.

在普通的 Java 类中,您阅读了这个静态字段。

<?xml version="1.0" encoding="UTF-8"?>
<web-app ...>
...
<context-param>
    <description>directory where the document would be uploaded</description>
    <param-name>directory</param-name>
    <param-value>/tmp</param-value>
</context-param>
...
</web-app>

And you can access this context parameter with ServletContext.getInitParameterfunction.

您可以使用ServletContext.getInitParameter函数访问此上下文参数。

If you are using Servlet 3.0 specification you can use annotations(http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/package-summary.html). I think that @WebInitParamis what are you looking for.

如果您使用的是 Servlet 3.0 规范,则可以使用注释(http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/package-summary.html)。我认为这@WebInitParam就是你要找的。

回答by Strength

I know it's so late but I had the same problem, so here's the solution below:

我知道太晚了,但我遇到了同样的问题,所以这是下面的解决方案:

To create web.xml:

创建 web.xml:

  1. Right click on your project
  2. Choose New
  3. Choose Other
  4. Box New file is opened, in Filter search web.xml
  5. You will get the file you want web.xml, then click next...then finish
  1. 右键单击您的项目
  2. 选择新建
  3. 选择其他
  4. Box 新文件被打开,在过滤器搜索 web.xml 中
  5. 你会得到你想要的文件web.xml,然后点击next...然后finish

(Tested on Netbean 7.4 JDK 7)

(在 Netbean 7.4 JDK 7 上测试)

回答by Mehandi Hassan

You need to firstly create a servlet page then web.xml will be generated in WEB.INF/

首先需要创建一个servlet页面,然后在WEB.INF/中生成web.xml

回答by Jonathan Manera

Try to right click the project and select New-> Other-> Web-> Standard Deployment Descriptor (web.xml)-> Next-> Finish. Follow that and it will be created in Configuration Files.

尝试右键单击该项目并选择New-> Other-> Web-> Standard Deployment Descriptor (web.xml)-> Next-> Finish。按照此操作,它将在配置文件中创建。

Video tutorial: https://www.youtube.com/watch?v=UAMOeHtPwrc

视频教程:https: //www.youtube.com/watch?v=UAMOeHtPwrc