WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

examples.servlets
Class SurveyServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--examples.servlets.SurveyServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class SurveyServlet
extends javax.servlet.http.HttpServlet

This example servlet takes input from a form and writes it out to a simple text file.

Note: This servlet has been modified from the SurveyServlet that is distributed with the JSDK2.0 so that it does not implement the SingleThreadModel.

The Survey servlet uses an initialization parameter to define the location of the text file containing the survey results. Initialization parameters are defined in the web.xml file that defines a Web Application, in this case the examplesWebApp. The web.xml file is located in your WebLogic Server distribution at config/examples/applications/examplesWebApp/WEB-INF/web.xml.

Build the Example

  1. Open a new command shell.

  2. Set up this development shell as described in Setting up Your Environment for Building and Running the Examples.

  3. Compile the servlet using the following command line:
     $ javac -d %EX_WEBAPP_CLASSES% SurveyServlet.java

  4. Start WebLogic Server with the examples configuration.

  5. Copy the file SurveyExample.html, located in the samples/examples/servlets directory in your WebLogic Server installation, to the config/examples/applications/examplesWebApp directory in your WebLogic Server installation. This directory is the location of the publicly-available files of the examplesWebApp.

Configure the Server

  1. Make sure that the examplesWebApp is deployed on your server.

  2. Make sure that the <init-param>resultsDir is defined and points to a valid directory. Make sure that the WebLogic Server has write permissions to this directory. The <init-param> is defined in the deployment descriptor for the examplesWebApp, located at /config/examples/applications/examplesWebApp/WEB-INF/web.xml in your WebLogic Server distribution. The <servlet> element registers the SurveyServlet. This attribute is set by default to the samples/examples/servlets directory in your WebLogic Server distribution.

Run the Example

Use a Web browser to load the following URL:
http://localhost:7001/examplesWebApp/SurveyExample.html

If the servlet executes correctly you will see a "Thank you for participating" message in the browser and the results of the survey will be written to a file called "Survey01Results.txt", located in the samples/examples/servlets directory in your WebLogic Server distribution.

Author:
Adapted from the JSDK2.0 by BEA Systems, Inc., Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.

Field Summary
(package private)  java.lang.String resultsDir
           
 
Constructor Summary
SurveyServlet()
           
 
Method Summary
 void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Writes survey results to an output file in response to the POSTed form.
 void init(javax.servlet.ServletConfig config)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
, doDelete, doGet, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resultsDir

java.lang.String resultsDir
Constructor Detail

SurveyServlet

public SurveyServlet()
Method Detail

doPost

public void doPost(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws javax.servlet.ServletException,
                   java.io.IOException
Writes survey results to an output file in response to the POSTed form. Writes a "thank you" message to the client.
Overrides:
doPost in class javax.servlet.http.HttpServlet

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet

Documentation is available at
http://e-docs.bea.com/wls/docs60

Copyright © 2000 BEA Systems, Inc. All Rights Reserved.