WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

examples.servlets
Class HelloWorld3

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

public class HelloWorld3
extends javax.servlet.http.HttpServlet

The HelloWorld3 example contains exactly the same Java code as the HelloWorld2 example, except that the initialization parameters are not defined in the web.xml file. The HelloWorld2 servlet uses initialization parameters to display two strings in the output ("Welcome WebLogic Developer!"). If the initialization parameters are not defined, the default strings defined in this example are used.

However, because initialization parameters are not defined for the HelloWorld3 servlet, the HelloWorld3 servlet checks for a request parameter called "name". If the "name" request parameter exists, the servlet uses its value in the greeting.

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. Build the servlet using ant:
      prompt> ant HelloWorld3

  4. Start WebLogic Server with the examples configuration.

Configure the Server

Make sure that the examplesWebApp is deployed on your server.

Run the Example

  1. Use a web browser to load the following URL:
    http://localhost:7001/examplesWebApp/HelloWorld3
    Note that the greeting displayed in your browser is "Hello World!"

  2. Now change the URL in your Web browser to
    http://localhost:7001/examplesWebApp/HelloWorld3?name=Alfred
    Note that the greeting displayed in your browser is now "Hello Alfred!"

There's More...

For more information on servlets, see Programming WebLogic HTTP Servlets.

Author:
Copyright (c) 1999-2002 by BEA Systems, Inc. All Rights Reserved.

Field Summary
(package private)  java.lang.String defaultGreeting
           
(package private)  java.lang.String defaultName
           
 
Constructor Summary
HelloWorld3()
           
 
Method Summary
 void init(javax.servlet.ServletConfig config)
           
 void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 
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, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultGreeting

java.lang.String defaultGreeting

defaultName

java.lang.String defaultName
Constructor Detail

HelloWorld3

public HelloWorld3()
Method Detail

init

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

service

public void service(javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse res)
             throws java.io.IOException
Overrides:
service in class javax.servlet.http.HttpServlet

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

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