WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

examples.servlets
Class SessionServlet

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

public class SessionServlet
extends javax.servlet.http.HttpServlet

This is a simple example of an HTTP servlet that uses the HttpSession class to track the number of times that a client has visited the servlet. Using session tracking provides an alternative method for tracking a client and storing client specific data, when the client browser does not support cookies. This is achieved by encoding a tracking id into the URLs in the hyperlinks of the HTML pages that are returned to the client.

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% SessionServlet.java

  4. Start WebLogic Server with the examples configuration.

Configure the Server

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

  2. If you wish to test this example with cookies turned off in your browser, make sure that session tracking via URLRewriting is configured in your examplesWebApp. By default, URLRewriting is not enabled.

Run the Example

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

  2. If you disable cookies in your browser and then click on the link in the example to ensure that URL rewriting is used, you can see that the session IDs are now included in the URL address bar of the browser.

There's More...

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

Author:
Copyright (c) 1996-98 by WebLogic, Inc. All Rights Reserved., Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.

Constructor Summary
SessionServlet()
           
 
Method Summary
 void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
, doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, 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

SessionServlet

public SessionServlet()
Method Detail

doGet

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

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

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