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 WebSphere Application Server or other J2EE-compliant Web servers.
To create a servlet using the Servlet wizard, complete the following steps:
From the Web perspective, expand your dynamic project in the Project Explorer view, and expand the Deployment Descriptor.
Right click on the Servlet icon, and select New > Servlet from the pop-up menu. The Create Servlet wizard appears.
In the Create a Servlet page, supply the following:
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.
Optionally add or remove initialization parameters and URL mappings.
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.
Optionally choose whether you want to generate an annotated servlet class.
If you selected an existing servlet class, click Finish; otherwise, select Next.
Supply the following information:
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.
Specify a superclass for the servlet class. A servlet created by this wizard can have javax.servlet.http.HttpServlet, or any class that has javax.servlet.http.HttpServlet in its hierarchy as its superclass. Click Browse to choose from the available superclasses.
Click Finish or click Next for more options.
Select a modifier to specify whether your servlet class is public, abstract, or final.
NOTE: Classes cannot be both abstract and final.
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.
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.
Click Finish. The servlet is generated.
Working in the Servlets page
In the Servlets page of the Web deployment descriptor editor, you can add an existing servlet or JSP file to the deployment descriptor or remove the selected servlet of JSP file from the deployment descriptor.
To work in the Servlets page, complete the following steps:
Open a Web project in the Project Explorer.
Double-click the Web project's Deployment Descriptor file in the Project Explorer. The Web deployment descriptor editor opens.
Click the Servlets tab to open the Servlets page.
You can edit settings in the following sections of the Servlets page:
Servlets and JSPs - list servlets and JSPs used in this application. You can add or remove servlets and JSPs from the list.
Details - lists details about the selected servlet or JSP. Details listed include the servlet class (canonical name), the display name (a short name for display purposes), and a description.
URL Mappings - lists URLs mapped to the selected servlet.
Initialization - lists the initialization parameters that are configured for the selected servlet or JSP file.
Load on Startup - enables you to specify the details of a servlet's load-on-startup element, including load order.
Security role references - list the security roles referenced in the Web application and lets you edit the security roles that are authorized to access the servlet. You can add or remove security roles. If you add a security role reference, you specify the role reference name, the role link, and a description.
Run as - lists details of the selected servlet's run-as element.
Icons - lets you view or change icons (small or large) used to represent the selected servlet or JSP file.
WebSphere Extensions - list and lets you change the details of the Servlet Extension for the selected servlet. You can add a new extension by clicking Add. The Add Markup Language entry wizard appears. Also, depending on the Servlet Version of the project you are working with, you can specify global and local transaction settings.