Unable to find web.xml in netbeans 7.0.1

杀马特。学长 韩版系。学妹 提交于 2019-12-03 13:19:03

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


EDIT (Aug 21, 2015)

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

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:

  1. Let's create a simple Java Web project with default settings.

  1. We're going to the project folder to inspect the contents of this folder:

note, that web folder is there.

  1. Navigating further:

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

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

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

You can create web.xml here:

or use Netbeans, as I described above.

Strength

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

To create 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

(Tested on Netbean 7.4 JDK 7)

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.

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

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.

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

You could use context-parameters in your web.xml

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

<?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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!