Adding and deleting servlets to a free-form project

You can add or delete servlet source code, annotated source or compiled class files to or from a free-form project.

Prerequisites

The servlet class must be an implementation of the following types:
javax.servlet.Servlet

javax.servlet.GenericServlet

javax.servlet.http.HttpServlet

Steps

  1. To add servlets to a free-form project, use your file management system to properly place your servlet artifacts into the free-form project. The directory name of the free-form project has the same string value you provided for the -project parameter used in the wrd-config command.
  2. The following activities occur when you drop a servlet into a free-form project:
    1. If necessary, the servlet class is generated and mapped to the imported_classes directory of the Web module project. The rapid deployment tools will then copy the class files to its appropriate J2EE location which is WebContent/WEB-INF/classes folder of the Web module project. The console output can look like this example when adding a servlet Java™ source file (called HelloServlet.java) to a free-form project (called MyProject):
      [06:52:23 PM] [/MyProject/servlet/HelloServlet.java] Added
      
      [06:52:26 PM] [/MyProject/bin/servlet/HelloServlet.class] copied to project [MyProjectWeb]
      
      [06:52:27 PM] Servlet added to web.xml: HelloServlet
      
      [06:52:27 PM] Servlet mapping added.  URL is: [MyProjectWeb/HelloServlet]
      
      Tip: If you want to monitor the rapid deployment activity, run your rapid deployment session with console output. You can complete this by running the rapid deployment launch tool as follows:
      • For Windowswrd.bat -monitor
      • For UNIXwrd.sh -monitor
    2. A new servlet entry and servlet mapping entry is created in the Web deployment descriptor (found in the WebContent\WEB-INF\web.xml file in the Web module project). The following is an example of the entries in web.xml:
      <servlet>
      
      	<servlet-name>HelloServlet</servlet-name>
      
      	<servlet-class>servlet.HelloServlet</servlet-class>
      
      </servlet>
      
      <servlet-mapping>
      
      	<servlet-name>HelloServlet</servlet-name>
      
      	<url-pattern>/HelloServlet</url-pattern>
      
      </servlet-mapping>
    3. The application is synchronized with the server.
  3. You can test the servlet running on the server, use the URL displayed in the console. In this example, the console output provided the following URL mapping information to the deployed servlet:
    [06:52:27 PM] Servlet mapping added.  URL is: [MyProjectWeb/HelloServlet]
    Type http://<machine_name>:<port>/MyProjectWeb/HelloServlet in the address bar and press Enter. Where <machine_name> is the host machine where WebSphere® Application Server runs. By default, WebSphere Application Server runs on port 9080.
  4. To delete servlets from a free-form project, use your file management system to properly remove your servlet artifacts from the free-form project. The directory name of the free-form project has the same string value you had provided for the -project parameter used in the wrd-config command.
  5. The following activities occur when you remove a servlet from the free-form project:
    1. The console output can look like this example when removing a servlet Java source file (called HelloServlet.java) from a free-form project (called MyProject):
      [07:03:42 PM] [/MyProject/bin/servlet/HelloServlet.class] Deleted
      
      [07:03:42 PM] [/MyProject/servlet/HelloServlet.java] Deleted
      
      [07:03:42 PM] Servlet Mapping removed from web.xml /HelloServlet
      
      [07:03:42 PM] Servlet removed from web.xml: HelloServlet
      
    2. The application is synchronized with the server.
Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.