Module servlet
[show private | hide private]
[frames | no frames]

Module servlet

Copyright 2004 Daniel J. Popowich

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

See handler for details about the servlet handler.

$Id: servlet.py,v 1.12 2005/02/12 04:10:00 popowich Exp $
Classes
HTMLPage HTMLPage is the servlet that most developers wanting to generate HTML will want to subclass.
Servlet Abstract base class for all mod_python servlets.

Function Summary
  handler(req)
This handler uses instances of subclasses of Servlet to handle HTTP GET and POST requests.

Function Details

handler(req)

This handler uses instances of subclasses of Servlet to handle HTTP GET and POST requests. These instances are referred to as servlets in this documentation.

Overview of how it works:
  1. A developer creates a class that subclasses Servlet or, more probably, HTMLPage, which already subclasses Servlet and has many features for generating HTML.
  2. Let's say we have a class named Foo that subclasses HTMLPage. This class must be saved in a file called Foo.mps. (mps stands for Mod Python Servlet).

    Generally, for any servlet named SERVLET, it must be a subclass of Servlet and saved in a file named SERVLET.mps.
  3. Apache needs to be configured to call this handler for Foo.mps. Assuming /var/www/html is your DocumentRoot and also assuming Foo.mps is saved in directory /var/www/html/mps_test then Apache needs the following configuration:
      <Directory /var/www/html/mps_test>
        SetHandler mod_python
        PythonHandler mod_python.servlet
        PythonDebug on
      </Directory>
    
  4. When the server receives a request for /mps_test/Foo it will look for a file named Foo.mps in /var/www/html/mps_test, compile the file, look for a class named Foo, insure it is a subclass of Servlet, create an instance of this class, let's call it servlet, and then call, in order:
    1. servlet.auth()
    2. servlet.prep()
    3. servlet.respond()
    4. servlet.wrapup()
    See the documentation for the above methods of Servlet for details about each stage of processing the request.
  5. Instances of a class are cached, so if a request for /mps_test/Foo comes in another request, the instance will be found in the cache and reused.

See the documentation for Servlet and HTMLPage for further details about servlet processing and helpful features.

If installed, see the tutorial for a live demonstration of servlets. See the README file that came with this distribution for tutorial installation instructions.

Generated by Epydoc 2.0 on Tue Mar 15 08:20:21 2005 http://epydoc.sf.net