Could not find web.xml in netbeans 7.0.1

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 will be loaded should be selected from the parameter in web.xml. I have not used web.xml before and I only know that it makes entries for each servlet. I can not see this file in my web application project, which I do in netbeans. Please help me with this. Thanks.

+6
source share
6 answers

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


EDIT (August 21, 2015)

Got downvote with duffymo comment that my answer is incorrect.

comment

And I decided to illustrate my answer with step by step pictures in order to avoid misunderstandings.

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

Linux:

  • Let me create a simple Java web project with default settings.

simple Linux web project

  1. We are going to the project folder to check the contents of this folder:

Linux web project folder

note that there is a web folder.

  1. Further:

contents of web folder on linux system

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

You can create the web.xml file in this folder manually or do it using Netbeans through the context menu of the project "New β†’ Create β†’ Other":

creating web.xml on linux system in netbeans # 1

creating web.xml on linux system in netbeans # 2

Now we go to the YOURPROJECT\web\WEB-INF\ folder to see that web.xml is:

created web.xml file

The same rules apply to the Windows operating system; check the following figures:

web application project folder on windows

web application folder contents on windows

Here you can create web.xml:

location of the web.xml file in windows

or use Netbeans as I described above.

+24
source

I know this so late, but I had the same problem, so here is the solution below:

To create web.xml:

  • Right click on your project
  • Select "New"
  • Choose others
  • A new file opens in the web.xml Search Filter field
  • You will get the file you want to use web.xml, then click next ... then complete

(Tested on Netbean 7.4 JDK 7)

+25
source

web.xml is optional in Java EE 6 . Thus, by default, it does not load into Netbeans . You need to manually download web.xml from Netbeans.

+6
source

Try right-clicking on the project and choosing New Other Web Standard Deployment Descriptor (web.xml) Next Finish . Follow this and it will be created in the configuration files.

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

+2
source

First you need to create a servlet page, then web.xml will be generated in WEB.INF /

+1
source

You can use contextual options in your web.xml

In your normal java class, you read these 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 using the ServletContext.getInitParameter function.

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

0
source

Source: https://habr.com/ru/post/955761/


All Articles