# Creating servlets

The servlet wizard helps you create Java™ servlets by walking you through the creation process and by providing you with output files that you can use or that you can modify for use with your Web application. The servlets can run on J2EE-compliant Web servers.

To create a servlet using the Servlet wizard, complete the following steps:

1. From the Web perspective, expand your dynamic project in the Project Explorer view, and expand the Deployment Descriptor.
2. Right click on the Servlet icon, and select New > Servlet from the pop-up menu. The Create Servlet wizard appears.
3. In the Create a Servlet page, supply the following:
   1. Type the name and description of the servlet. Notice that the name that you type in the name field is used as the default URL mapping.
   2. Optionally add or remove initialization parameters and URL mappings.
   3. Optionally choose an existing servlet class. To do this, select the Use existing servlet class check box, and then select the Browse button. A window appears in which you can choose an existing servlet or a JSP.
   4. Optionally choose whether you want to generate an annotated servlet class.
   5. If you selected an existing servlet class, click Finish; otherwise, select Next.
4. Supply the following information:
   1. Specify the folder where the servlet class will be placed, the package that the class will belong to (it is added into a default package if you do not specify one), and the class name of the servlet.
   2. Specify a superclass for the servlet class. A servlet created by this wizard can have HttpServlet, or any class that has HttpServlet in its hierarchy as its superclass. Click Browse to choose from the available superclasses.
   3. Click Finish or click Next for more options.
5. Select a modifier to specify whether your servlet class is public, abstract, or final. (Classes cannot be both abstract and final.)
   1. The javax.servlet.Servlet is provided as the default Interface. You can also add additional interfaces to implement. Click Add to open the Interface Selection dialog.

      In this dialog, as you type the name of the interface that you are interested in adding in the Choose interfaces field, the list of available interfaces listed in the Matching types list box updates dynamically to display only the interfaces that match the pattern. Choose an interface to see the Qualifier, and then click Add. Click OK when you are finished.

   2. Select any appropriate method stubs to be created in the servlet file. The stubs created by using the Inherited abstract methods option must be implemented if you do not intend to create an abstract servlet. This is not true for Constructors from superclass.
   3. Click Finish. The servlet is generated.

Related concepts
Servlets
The Web deployment descriptor editor

Related tasks
Configuring Web applications using the Web deployment descriptor editor

(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.