Servlet in NetBeans

To create the Servlet in NetBeans,So follow some steps:-
  1. Go to the File menu, select New Project.
  2. Choose the Category of project as Web.
  3. Choose the Project type as Web Application.
  4. Enter a Project Name
  5. Use the default context path, and use J2EE 1.5 or greater.
  6. Select Tomcat as the Server.
  7. Set the Java EE version to J2EE 1.5 or greater.
  8. After clicking finish, there should be a project listed in your Projects tab.

  9. Servlet in Netbeans


Right-click on Source Packages and select New, then select Java Package.

Servlet in Netbeans new project select


Give full name of the Java package, for instance my.pack, then click Finish.

Servlet in Netbeans package name

Right click on the new package and create a new class.

Servlet in Netbeans new class


Servlet in Netbeans new class next


After completing these steps, you can see the servlet in the Source Packages folder.
Servlet in Netbeans in Source package


Open the web.xml file. There are many ways to view the contents of the web.xml file, click the XML tab above the edit window to view the XML source.

Servlet in Netbeans XML file


Define the servlet and servlet-mapping tags.

Servlet in Netbeans mapping tags

If you try to run the servlet and get a log in screen for the manager, then you will need to set the username and password for the manager. Do this from theTools -> Server Manager menu (Tools -> Servers in NetBeans 6.0).

Servlet in Netbeans entry

Including Source Files in the WAR File


By default, the .java files are not added to the WAR file and properties screen, select Build -> Packaging. Edit the Exclude From WAR File box and remove **/*.java,.

Servlet in Netbeans war create

Additional features will be added to a web application by using jar files. Download the jar file to your system, then right-click the Libraries folder and select Add JAR/Folder.
Servlet in Netbeans jar create

Whenever the project is cleaned and built (select Clean and Build from the Build menu), a Web Archive (WAR) file is created. This WAR file is actually a ZIP file that contains the web application. The WAR file contains a web application that has a standard format. The WAR file is located under the Files tab in the dist folder.

Servlet in Netbeans war file