Home
Adding the ListAccounts servlet to the Web project
RAD v7.5 provides a servlet wizard to assist you in adding servlets to your Web application. Follow these steps:
Select File Æ New Æ Other Æ Web Æ Servlet and click Next.
Tip: The Create Servlet wizard can also be accessed by right-clicking the project and selecting New Æ Servlet.
The first page of the Create Servlet wizard opens. Type itso.rad75.webapps.servlet as the package and ListAccounts as the class name. Click Next.
Figure 13-28 New Servlet wizard (1)
The second page provides space for the name and description of the new servlet.
Figure 13-29 New Servlet wizard (2)
The page also allows the addition of servlet initialization parameters, which are used to parameterize a servlet. Servlet initialization parameters can be changed at runtime from within the WebSphere Application Server administrative console.
The wizard will automatically generate the URL mapping /ListAccounts for the new servlet. If a different, or additional URL mappings are required, these can be added here.
In our sample, we do not require additional URL mappings or initialization parameters. Click Next.
The third and final page gives the option to have the wizard create stubs methods for methods available from the HttpServlet interface. The init method is called at startup and destroy is called at shutdown.
The doPost, doGet, doPut, and doDelete methods are called when an HTTP request is received for this servlet. All of the do methods have two parameters, namely an HttpServletRequest and an HttpServletResponse. It is the job of these methods to extract the pertinent details from the request and populate the response object.
Figure 13-30 New Servlet wizard page (3)
For the ListAccounts servlet, only doGet and doPost should be selected. Usually, HTTP gets are used with direct links, when no information has to be sent to the server. HTTP posts are typically used when information in a form has to be sent to the server.
There is no initialization required for our new servlet and so the init method is not selected.
Click Finish. The servlet is generated and added to the project. The source code can be found in the Java Resources folder of the project, while the configuration for the servlet is found in Servlets tab of the Web deployment descriptor.
Now expand the deployment descriptor for the RAD75BankBasicWeb (immediately under the project in the Enterprise Explorer), and you see that the ListAccounts servlet is listed.
ibm.com/redbooks