WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.servlets.wrapper

This example demonstrates how to write Servlet Wrappers.

See:
          Description

Class Summary
CustomOutputStream CustomOutputStream is a user defined custom OutputStream that substitutes the replace value for the key value in all output.
MyResponseWrapper MyResponseWrapper is a class that extends the HttpServletResponseWrapper for to modify the HttpServlet Response.
SubstFilter SubstFilter is a servlet filter that sets init parameters from the web.xml file, and passes them on to the wrapper to modify the servlet response.
 

Package examples.servlets.wrapper Description

This example demonstrates how to write Servlet Wrappers.

MyResponseWrapper is a servlet wrapper that modifies the response of a web application. This example defines a CustomOutputStream which overrides the normal output stream. This OutputStream replaces the value of the servlet parameter "keytext" with the value of "replaceText". These are passed as init-parameters by the web.xml file, so the user must edit the web.xml file to change the original output to be replaced or the output with which to replace it.

See:
          Description

Additional Resources for examples.servlets.wrapper
build.xml The Ant build script that assembles and deploys the application.
web.xml Web Application deployment descriptor. The descriptor configures the filter on the application and passes in the init-parameters that the customOutputStream uses for substitution.
 

Package examples.servlets.wrapper Description

The wrapper webapp uses the MyResponseWrapper class which overrides the HttpServletResponseWrapper class to provide for a custom response output.

  1. CustomOutputStream.java actually modifies the output of the webApp.
  2. MyResponseWrapper.java is the wrapper for the webapp that modifies the response. This wrapper is called by the SubstFilter servlet filter set up in the web.xml file.
  3. SubstFilter.java triggers the wrapper.

Perform the following steps in order to build and run the example:

  1. Build the example
  2. Run the example

Build the Example

  1. Set up your development shell as described in Setting up your environment.

  2. Compile the example by executing an ant build script or a command.

Run the Example

  1. Start WebLogic Server with the examples configuration.

  2. Load the wrapperWebApp Web Application into a browser using a URL such as:
      http://hostname:port/wrapperWebApp
    where:
    hostname
    Host name of the WebLogic Server
    port
    Port where the WebLogic Server is listening for connections

  3. This URL will point you to the HelloWorld.jsp that has been packaged from the %SAMPLES_HOME%\server\src\samples\examples\jsp directory. Notice that the value of the keyText specified in the web.xml has been replaced with the value of replaceText. By default, these values are set to "World" and "Developer".


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

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