WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

examples.i18n.logging.message
Class UserSMessagesServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--examples.i18n.logging.message.UserSMessagesServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class UserSMessagesServlet
extends javax.servlet.http.HttpServlet

UserSMessagesServlet is a simple servlet which shows how to use WebLogic i18n to log your own application's info and error messages to the server log. There is a similar example showing how to do the same thing from a startup class instead of a servlet.

After running the example once, change your host computer's locale from "English" to "German" or "French" and reboot the WebLogic server. Run the example again and note that the example's log messages are displayed in either "German" or "French" depending upon your settings.

The following section describes how to build and run the examples:

  1. Build the example
  2. Configure the server
  3. Run the example

Note: Before you build the example add the following entry in your web.xml file located at %WL_HOME%/samples/server/stage/examples/examplesWebApp/WEB-INF/ directory.

where:

%WL_HOME%
WebLogic Server installation directory.
   <servlet>
     <servlet-name>UserSMessagesServlet</servlet-name>
     <servlet-class>examples.i18n.logging.message.UserSMessagesServlet</servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>UserSMessagesServlet</servlet-name>
     <url-pattern>/UserSMessagesServlet/*</url-pattern>
   </servlet-mapping>
 

Build the example

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

    We provide a build script for you to build the example, called build.xml.

  2. Run the build script using the following Java ant command:
            $ ant
  3. The script builds the example and places the files in the samples\examples\i18n\logging directory of your WebLogic Server installation.

This script will compile the servlet, process the UserServerSVExample.xml catalog, and produce the logging class. This class contains static methods for logging messages to the WebLogic Server error log.

Configure the server

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

Run the example

  1. Start the WebLogic Server with the examples configuration.

  2. Use a web browser to load the following URL:
    http://localhost:7001/examplesWebApp/UserSMessagesServlet

  3. You should receive output similar to this in your WL_HOME/weblogic700/samples/server/config/examples/examplesServer/examplesServer.log file:
    
     First message was logged at 1/5/01.
     The servlet request was a GET and the number is 32,767.
     This is not really an error, the example has finished normally.
     

Copyright (c) 2000-2002 by BEA Systems, Inc. All Rights Reserved.


Constructor Summary
UserSMessagesServlet()
           
 
Method Summary
 void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          service() method.
 
Methods inherited from class javax.servlet.http.HttpServlet
, doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserSMessagesServlet

public UserSMessagesServlet()
Method Detail

service

public void service(javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse res)
             throws java.io.IOException,
                    javax.servlet.ServletException
service() method.
Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
req - HTTP servlet request
res - HTTP servlet response
Throws:
java.io.IOException - if problem occurs with an I/O operation
javax.servlet.ServletException - if problem occurs with servlet operation

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

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