Solutions Products Services

Search
Download Contact Us
Documentation Site map
Support About Us
E-commerce SolutionsiPlanet



Creating Servlets

  1. In the Explorer, select the WebModule | WEB-INF | Classes node of the Hello web module you just created in previous section 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 the context menu and select New | JSP & Servlet | Servlet.

    The New From Template Wizard appears:

  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. Add a static integer variable and a print line to display Hello. You are visitor 1 as follows:

    static int counter= 1;
    /** Processes requests for both HTTP GET and POST methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
        response.setContentType("text/html");
        java.io.PrintWriter out = response.getWriter();
        /* output your page here */
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("Hello.  You are visitor "+(counter++));
        out.println("</body>");
        out.println("</html>");
        out.close();
    } 
    

  8. Select the WEB-INF node.
  9. Right click to display the context menu and select Properties.
  10. In the Properties tab, verify that the Context Root field is defined to your project's directory (e.g. WebModule).
  11. Close the Properties window.
  12. From the Explorer window Filesystems tab, select the HelloServlet node.
  13. From the Build menu select Deploy.

    The IDE content menu status field indicates that the deployment action was successful. You can also see this from the output window.

  14. Right click on the HelloServlet node once more and select Execute.

    The execution and output windows appear. In the IDE status bar, messages are displayed to indicate that the iPlanet Web Server is getting started (or restarted), and the Web browser opens.

    When the iPlanet Web Server is starting, a WAR file is created and the servlet is deployed to the default virtual server instance.

    The browser opens to the http://serverinstance/WebModule/servlet/myPackage/HelloServlet URL.

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

The next step in the iPlanet Web Server Integration Module Tutorial is learning more about executing and debugging.

 
   

Legal Notices


Search