Purple Code

com.purpletech.servlets
Class DefaultServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--com.purpletech.servlets.DefaultServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ImageServlet

public class DefaultServlet
extends javax.servlet.http.HttpServlet

A servlet that keeps its own list of default parameters, which it uses in case a requested parameter was unspecified by the user or the sysadmin. It uses the same list for page params and init params.

It also overrides log() to stash the messages in a private string buffer. Subclasses can access this with the getLog() and getLogHTML() methods. The idea is that during development, servlets may want to output the logs directly on each page request (so the developer doesn't have to go looking in the file system for a log file that probably wasn't flushed anyway).

See Also:
Serialized Form

Field Summary
protected  java.lang.StringBuffer logBuffer
           
 
Constructor Summary
DefaultServlet()
           
 
Method Summary
 java.lang.String getInitParameter(java.lang.String name)
          Overrides standard getInitParameter.
 java.lang.String getLog()
           
 java.lang.String getLogHTML()
           
 java.lang.String getParameter(javax.servlet.http.HttpServletRequest req, java.lang.String name)
          Overrides standard getParameter.
 java.lang.String getServletInfo()
           
 void log(java.lang.String s)
           
 void log(java.lang.Throwable t)
           
protected  void setDefaults(java.util.Dictionary d)
          Set the list of default parameters.
protected  void setDefaults(java.lang.String[][] d)
          Set the list of default parameters.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logBuffer

protected java.lang.StringBuffer logBuffer
Constructor Detail

DefaultServlet

public DefaultServlet()
Method Detail

getParameter

public java.lang.String getParameter(javax.servlet.http.HttpServletRequest req,
                                     java.lang.String name)
Overrides standard getParameter. If parameter not found in the standard way, looks inside defaults.


getInitParameter

public java.lang.String getInitParameter(java.lang.String name)
Overrides standard getInitParameter. If parameter not found in the standard way, looks inside defaults. Warning -- to be safe, you must not use the same name for initParameters and page Parameters.

Specified by:
getInitParameter in interface javax.servlet.ServletConfig
Overrides:
getInitParameter in class javax.servlet.GenericServlet

setDefaults

protected void setDefaults(java.util.Dictionary d)
Set the list of default parameters.

Parameters:
d - the name-value pairs

setDefaults

protected void setDefaults(java.lang.String[][] d)
Set the list of default parameters. The argument is a 2-D string array.

Subclasses need to call this method in their init() method. For example:

 String[][] defaults = { {"username", "bodiddley" }    
                         {"password", "lovehate" }     
                         {"datasource", "jdbc:odbc:MyData" } 
                       };  
 public void init(ServletConfig cfg) {
	super.init(cfg);
 	setDefaults(defaults);
 }
 

(Note that it's OK to name your variable defaults too because this class' variable is private, hence shadowed in subclasses.)

If you have multiple levels of subclasses, just make sure you call super.init(cfg) at the top of your init() method (before you call setDefaults(). That way, the superclass will set its defaults, then you can set yours (and possibly override the superclass' values).

Parameters:
d - the name-value pairs

log

public void log(java.lang.String s)
Overrides:
log in class javax.servlet.GenericServlet

log

public void log(java.lang.Throwable t)

getLog

public java.lang.String getLog()

getLogHTML

public java.lang.String getLogHTML()

getServletInfo

public java.lang.String getServletInfo()
Specified by:
getServletInfo in interface javax.servlet.Servlet
Overrides:
getServletInfo in class javax.servlet.GenericServlet

Documentation generated March 5 2003