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
Unable to find web.xml in netbeans 7.0.1
提问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-INF
folder, 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 的反对票,我的回答不正确。
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:
- Let's create a simple Java Web project with default settings.
- 让我们使用默认设置创建一个简单的 Java Web 项目。
- We're going to the project folder to inspect the contents of this folder:
- 我们将转到项目文件夹以检查此文件夹的内容:
note, that web
folder is there.
请注意,该web
文件夹在那里。
- Navigating further:
- 进一步导航:
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 执行此操作:
Now, we're navigating YOURPROJECT\web\WEB-INF\
folder to see, that web.xml
is there:
现在,我们正在浏览YOURPROJECT\web\WEB-INF\
文件夹以查看,就web.xml
在那里:
The same rules are correct for windows operating system, check the pictures below:
相同的规则适用于 windows 操作系统,请查看下图:
You can create web.xml here:
您可以在此处创建 web.xml:
or use Netbeans, as I described above.
或使用 Netbeans,如上所述。
回答by Masudul
web.xml
is optional in Java EE 6
. So, by default it is not loaded in Netbeans
. You need to manually load web.xml
from Netbeans.
web.xml
在Java 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.getInitParameter
function.
您可以使用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 @WebInitParam
is 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:
- Right click on your project
- Choose New
- Choose Other
- Box New file is opened, in Filter search web.xml
- You will get the file you want web.xml, then click next...then finish
- 右键单击您的项目
- 选择新建
- 选择其他
- Box 新文件被打开,在过滤器搜索 web.xml 中
- 你会得到你想要的文件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