Servlet Sample

Download

The following sample contains a server definition which supports servlets using a default configuration setting for HTTP transport and webcontainer.

Description

The DefaultServletEngine sample contains a server definition which supports servlets using default configuration settings for the HTTP transport and webcontainer. It also contains a very simple web application, ServletApp.war, which contains a single Servlet, SimpleServlet. This servlet prints the following message in your browser window: "Simple Servlet ran successfully".

This sample can be installed onto runtime versions 8.5.0.0 and later.

Instructions

To run the ServletApp application:

  1. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar ServletSample.jar
  2. Start the ServletSample server by running the command below from the bin directory in the Liberty profile installation:
    server run ServletSample
  3. Confirm the application started by looking for the following message in the log:
    CWWKZ0001I: Application ServletApp started in XX.XX seconds.
  4. In your browser, enter the URL for the application: http://localhost:9122/ServletApp/ (where port 9122 assumes the httpEndpoint provided in the sample server.xml has not been modified).
  5. In your browser, you should see the message
    Simple Servlet ran successfully

Notes

The ServletApp.war file contains the source and binaries for the application, and can be used to import it to Eclipse.

The application is automatically installed because it is located in the server dropins directory. Any number of applications can be installed from this location.

Sample Structure

    • - wlp
      • - usr
        • - servers
          • - ServletSample
            • - dropins
              • - ServletApp.war
            • - server.xml
            • - readme.html
            • - Copyright.txt