Part 4: Creating Servlets

  1. In the Explorer, select the WebModule -> WEB-INF -> Classes node of the Hello web module you just created in Part 3 of this tutorial.

    Servlets must be created in a web module and therefore must reside in a package located under the WEB-INF/Classes directory of the web module.

  2. Right click and select New Package.

  3. Enter the name "myPackage" in the Create New Package window and select OK.

  4. From the Explorer window, select the myPackage node.
  5. Right click to display a popup menu and select New > JSP & Servlet > Servlet.

  6. Enter HelloServlet in the Name field and select the Finish button.

    The HelloServlet node appears in the Explorer and opens in the Source Editor.

  7. Uncomment the out.println code.
  8. Add a string variable and output print line to display "Hello Everyone!" as follows:

    /* output your page here */
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    String greeting = "Kamille";
    out.println("<h1>Hello Everyone from " + greeting +"!</h1>");
    out.println("</body>");
    out.println("</html>");
    out.close();
    }
    

  9. From the Explorer window, select the HelloServlet node.
  10. Right click to display the context menu and select execute.

    The execution and output window appear. In the status bar, messages are displayed to indicate that the iPlanet Application Server is getting started (or restarted). The WAR file is getting deployed, and the Web browser is opening.

    When the iPlanet Application Server is starting, the KJS process you launched from the previous section is killed. Then the WAR file is created and deployed and a new KJS process is started.

    The Forte browser opens to http://<server>/NASApp/<webmodule>/HelloServlet URL.

Congratulations, you have successfully created a simple servlet in a web module, deployed the web module to the iPlanet Application Server, and executed it!

See also
  Performing Local Debugging


Legal Notices