To create a servlet, use the Servlet wizard to create the servlet class source file and implement the required methods in the file. The method is described below.
Creating a New Servlet
From the [New] wizard, select [Web] > [Servlet], and the wizard creates the servlet. Refer to the following for the wizard settings:
Web project
Specify the project that stores the servlet class source.
Source folder
Specify the folder that stores the servlet class source.
Java package
Specify the servlet class package name.
Class name
Specify the class name of the servlet class.
Superclass
Specify the class to be inherited.
Servlet Name, Description, Initialization Parameters, and URL Mappings
Specify the servlet definition information. The content specified here is inserted in the deployment descriptor (web.xml) of the Web application.
Modifiers
Specify the modifiers of the servlet class.
Interfaces
Specify the interface to be implemented.
Which method stubs would you like to create?
Select the method stubs to be implemented.
When the wizard is executed, the servlet class Java source is generated and the required description is added to web.xml.
Editing the Servlet
After the source is generated, implement the doPost() and doGet() servlet methods. These methods usually implement processing in the following sequence:
Get the parameter values from the request object.
Set headers in the response object.
Get the output stream from the response object and output response to the response object.
The way to implement these methods is the same as for an ordinary Java class. Use the Java editor to implement the methods.