Skip to content
Related Articles

Related Articles

Steps to Create a Servlet

View Discussion
Improve Article
Save Article
  • Last Updated : 20 Feb, 2022

Today we all are aware of the need of creating dynamic web pages i.e the ones which have the capability to change the site contents according to the time or are able to generate the contents according to the request received by the client. If you like coding in Java, then you will be happy to know that using Java there also exists a way to generate dynamic web pages and that way is Java Servlet. But before we move forward with our topic let’s first understand the need for server-side extensions.  

Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver.  

Properties of Servlets are as follows:

  • Servlets work on the server-side.
  • Servlets are capable of handling complex requests obtained from the webserver.

Creating using NetBeans IDE

Firstly We are Using NetBeans IDE For Creating the Servlet. So Now, Welcome simply displays Welcome <Username>!. Create using NetBeans IDE. Right-click Sources Package directory, select New > Servlet.. as shown in Fig.1. Then, the New Servlet dialog box appears.

Creating Servlet

Fig.1 : Creating Servlet

Now, Enter Welcome Servlet in the Class Name textbox and enter servlet in the Package textbox as shown in diagram Fig.2. 

Fig.2: Entering the class name and the package

Then, click Next. Now The Configure Servlet Deployment section of the New Servlet dialog box appears. Whereas, Keep the defaults but select the option Add information to deployment descriptor (web.xml) as shown in Fig. 3.

Fig.3: Configuring the Servlet deployment

We Want to Create a deployment descriptor web.xml to take precedence over annotations. This means a deployment descriptor web.xml will be created instead of using Annotations. Enter the information Class name for the Servlet, A Servlet Name to it, and the URL Pattern(s) within for it. In the Servlet API version 3.0 onwards, the deployment descriptor [web.xml] takes precedence over annotations. Click On Finish.

Using the Servlet package, Servlet is Created Now With The Servlet named is created under the servlet package. The is available with the default skeleton created by NetBeans IDE which needs to be modified to hold the actual code spec.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!