org.apache.struts.action
Class ActionServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--org.apache.struts.action.ActionServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ActionComponentServlet

public class ActionServlet
extends javax.servlet.http.HttpServlet

ActionServlet represents the "controller" in the Model-View-Controller (MVC) design pattern for web applications that is commonly known as "Model 2". This nomenclature originated with a description in the JavaServerPages Specification, version 0.92, and has persisted ever since (in the absence of a better name).

Generally, a "Model 2" application is architected as follows:

The standard version of ActionServlet implements the following logic for each incoming HTTP request. You can override some or all of this functionality by subclassing this servlet and implementing your own version of the processing.

The standard version of ActionServlet is configured based on the following servlet initialization parameters, which you will specify in the web application deployment descriptor (/WEB-INF/web.xml) for your application. Subclasses that specialize this servlet are free to define additional initialization parameters. Several of these were deprecated between the 1.0 and 1.1 releases. The deprecated parameters are listed after the nominal parameters.

The following parameters may still be used with the Struts 1.1 release but are deprecated.

Version:
$Revision: 1.1 $ $Date$
Author:
Craig R. McClanahan, Ted Husted, Martin Cooper, David Graham
See Also:
Serialized Form

Field Summary
protected  java.lang.String config
          Comma-separated list of context-relative path(s) to our configuration resource(s) for the default module.
protected  org.apache.commons.digester.Digester configDigester
          The Digester used to produce ModuleConfig objects from a Struts configuration file.
protected  boolean convertNull
          The flag to request backwards-compatible conversions for form bean properties of the Java wrapper class types.
protected  org.apache.commons.collections.FastHashMap dataSources
          The JDBC data sources that has been configured for this module, if any, keyed by the servlet context attribute under which they are stored.
protected  int debug
          Deprecated.  
protected  MessageResources internal
          The resources object for our internal resources.
protected  java.lang.String internalName
          The Java base name of our internal resources.
protected static org.apache.commons.logging.Log log
          Commons Logging instance.
protected  RequestProcessor processor
          The RequestProcessor instance we will use to process all incoming requests.
protected  java.lang.String[] registrations
          The set of public identifiers, and corresponding resource names, for the versions of the configuration file DTDs that we know about.
protected  java.lang.String servletMapping
          The URL pattern to which we are mapped in our web application deployment descriptor.
protected  java.lang.String servletName
          The servlet name under which we are registered in our web application deployment descriptor.
 
Fields inherited from class javax.servlet.http.HttpServlet
 
Constructor Summary
ActionServlet()
           
 
Method Summary
 void addServletMapping(java.lang.String servletName, java.lang.String urlPattern)
          Remember a servlet mapping from our web application deployment descriptor, if it is for this servlet.
private  void defaultControllerConfig(ModuleConfig config)
          Deprecated. Will be removed in a release after Struts 1.1.
private  void defaultFormBeansConfig(ModuleConfig config)
          Deprecated. Will be removed in a release after Struts 1.1.
private  void defaultForwardsConfig(ModuleConfig config)
          Deprecated. Will be removed in a release after Struts 1.1.
private  void defaultMappingsConfig(ModuleConfig config)
          Deprecated. Will be removed in a release after Struts 1.1.
private  void defaultMessageResourcesConfig(ModuleConfig config)
          Deprecated. Will be removed in a release after Struts 1.1.
 void destroy()
          Gracefully shut down this controller servlet, releasing any resources that were allocated at initialization.
protected  void destroyApplications()
          Deprecated. replaced by destroyModules()
protected  void destroyConfigDigester()
          Gracefully release any configDigester instance that we have created.
protected  void destroyDataSources()
          Deprecated. Will no longer be required with module support
protected  void destroyInternal()
          Gracefully terminate use of the internal MessageResources.
protected  void destroyModules()
          Gracefully terminate use of any modules associated with this application (if any).
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process an HTTP "GET" request.
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process an HTTP "POST" request.
 javax.sql.DataSource findDataSource(java.lang.String key)
          Deprecated. Look up data sources directly in servlet context attributes
 ActionFormBean findFormBean(java.lang.String name)
          Deprecated. Replaced by ModuleConfig.findFormBeanConfig()
 ActionForward findForward(java.lang.String name)
          Deprecated. Replaced by ModuleConfig.findForwardConfig()
 ActionMapping findMapping(java.lang.String path)
          Deprecated. Replaced by ModuleConfig.findActionConfig()
protected  ApplicationConfig getApplicationConfig(javax.servlet.http.HttpServletRequest request)
          Deprecated. use getModuleConfig(HttpServletRequest)
 int getDebug()
          Deprecated. Configure the logging detail level in your underlying logging implementation
 MessageResources getInternal()
          Return the MessageResources instance containing our internal message strings.
protected  ModuleConfig getModuleConfig(javax.servlet.http.HttpServletRequest request)
          Return the module configuration object for the currently selected module.
protected  RequestProcessor getRequestProcessor(ModuleConfig config)
          Look up and return the RequestProcessor responsible for the specified module, creating a new one if necessary.
 MessageResources getResources()
          Deprecated. Actions should call Action.getResources(HttpServletRequest) instead of this method, in order to retrieve the resources for the current module.
private  void handleConfigException(java.lang.String paths, java.lang.Exception e)
          Simplifies exception handling in the parseModuleConfigFile() method.
 void init()
          Initialize this servlet.
protected  ApplicationConfig initApplicationConfig(java.lang.String prefix, java.lang.String path)
          Deprecated. use initModuleConfig(String,String)
protected  void initApplicationDataSources(ModuleConfig config)
          Deprecated. use initModuleDataSources(ModuleConfig)
protected  void initApplicationMessageResources(ModuleConfig config)
          Deprecated. use initModuleMessageResources()
protected  void initApplicationPlugIns(ModuleConfig config)
          Deprecated. use initModulePlugIns(ModuleConfig)
protected  org.apache.commons.digester.Digester initConfigDigester()
          Create (if needed) and return a new Digester instance that has been initialized to process Struts module configuraiton files and configure a corresponding ModuleConfig object (which must be pushed on to the evaluation stack before parsing begins).
protected  void initDataSources()
          Deprecated. Replaced by initApplicationDataSources() that takes an ModuleConfig argument. This method does nothing.
protected  void initInternal()
          Initialize our internal MessageResources bundle.
protected  ModuleConfig initModuleConfig(java.lang.String prefix, java.lang.String paths)
          Initialize the application configuration information for the specified module.
protected  void initModuleDataSources(ModuleConfig config)
          Initialize the data sources for the specified module.
protected  void initModuleMessageResources(ModuleConfig config)
          Initialize the application MessageResources for the specified module.
protected  void initModulePlugIns(ModuleConfig config)
          Initialize the plug ins for the specified module.
protected  void initOther()
          Initialize other global characteristics of the controller servlet.
protected  void initServlet()
          Initialize the servlet mapping under which our controller servlet is being accessed.
 void log(java.lang.String message, int level)
          Deprecated. Use commons-logging instead.
private  void parseModuleConfigFile(java.lang.String prefix, java.lang.String paths, ModuleConfig config, org.apache.commons.digester.Digester digester, java.lang.String path)
          Parses one module config file.
protected  void process(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Perform the standard request processing for this request, and create the corresponding response.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
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

config

protected java.lang.String config
Comma-separated list of context-relative path(s) to our configuration resource(s) for the default module.


configDigester

protected org.apache.commons.digester.Digester configDigester
The Digester used to produce ModuleConfig objects from a Struts configuration file.

Since:
Struts 1.1

convertNull

protected boolean convertNull
The flag to request backwards-compatible conversions for form bean properties of the Java wrapper class types.

Since:
Struts 1.1

dataSources

protected org.apache.commons.collections.FastHashMap dataSources
The JDBC data sources that has been configured for this module, if any, keyed by the servlet context attribute under which they are stored.


debug

protected int debug
Deprecated.  

The debugging detail level for this servlet.


internal

protected MessageResources internal
The resources object for our internal resources.


internalName

protected java.lang.String internalName
The Java base name of our internal resources.

Since:
Struts 1.1

log

protected static org.apache.commons.logging.Log log
Commons Logging instance.

Since:
Struts 1.1

processor

protected RequestProcessor processor
The RequestProcessor instance we will use to process all incoming requests.

Since:
Struts 1.1

registrations

protected java.lang.String[] registrations
The set of public identifiers, and corresponding resource names, for the versions of the configuration file DTDs that we know about. There MUST be an even number of Strings in this list!


servletMapping

protected java.lang.String servletMapping
The URL pattern to which we are mapped in our web application deployment descriptor. FIXME - multiples???


servletName

protected java.lang.String servletName
The servlet name under which we are registered in our web application deployment descriptor.

Constructor Detail

ActionServlet

public ActionServlet()
Method Detail

destroy

public void destroy()
Gracefully shut down this controller servlet, releasing any resources that were allocated at initialization.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

init

public void init()
          throws javax.servlet.ServletException
Initialize this servlet. Most of the processing has been factored into support methods so that you can override particular functionality at a fairly granular level.

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException - if we cannot configure ourselves correctly

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws java.io.IOException,
                  javax.servlet.ServletException
Process an HTTP "GET" request.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet exception occurs

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException,
                   javax.servlet.ServletException
Process an HTTP "POST" request.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet exception occurs

addServletMapping

public void addServletMapping(java.lang.String servletName,
                              java.lang.String urlPattern)
Remember a servlet mapping from our web application deployment descriptor, if it is for this servlet.

Parameters:
servletName - The name of the servlet being mapped
urlPattern - The URL pattern to which this servlet is mapped

findDataSource

public javax.sql.DataSource findDataSource(java.lang.String key)
Deprecated. Look up data sources directly in servlet context attributes

Return a JDBC data source associated with this module, if any.

Parameters:
key - The servlet context attribute key under which this data source is stored, or null for the default.

findFormBean

public ActionFormBean findFormBean(java.lang.String name)
Deprecated. Replaced by ModuleConfig.findFormBeanConfig()

Return the form bean definition associated with the specified logical name, if any; otherwise return null.

Parameters:
name - Logical name of the requested form bean definition

findForward

public ActionForward findForward(java.lang.String name)
Deprecated. Replaced by ModuleConfig.findForwardConfig()

Return the forwarding associated with the specified logical name, if any; otherwise return null.

Parameters:
name - Logical name of the requested forwarding

findMapping

public ActionMapping findMapping(java.lang.String path)
Deprecated. Replaced by ModuleConfig.findActionConfig()

Return the ActionMapping for the specified path, for the default module.

Parameters:
path - Request path for which a mapping is requested

getDebug

public int getDebug()
Deprecated. Configure the logging detail level in your underlying logging implementation

Return the debugging detail level for this servlet.


getInternal

public MessageResources getInternal()
Return the MessageResources instance containing our internal message strings.

Since:
Struts 1.1

getResources

public MessageResources getResources()
Deprecated. Actions should call Action.getResources(HttpServletRequest) instead of this method, in order to retrieve the resources for the current module.

Return the application resources for the default module, if any.


log

public void log(java.lang.String message,
                int level)
Deprecated. Use commons-logging instead.

Log the specified message if the current debugging detail level for this servlet has been set to an equal or higher value. Otherwise, ignore this message.

Parameters:
message - Message to be logged
level - Debugging detail level of this message

destroyApplications

protected void destroyApplications()
Deprecated. replaced by destroyModules()

Gracefully terminate use of any modules associated with this application (if any).

Since:
Struts 1.1

destroyModules

protected void destroyModules()
Gracefully terminate use of any modules associated with this application (if any).

Since:
Struts 1.1

destroyConfigDigester

protected void destroyConfigDigester()
Gracefully release any configDigester instance that we have created.

Since:
Struts 1.1

destroyDataSources

protected void destroyDataSources()
Deprecated. Will no longer be required with module support

Gracefully terminate use of the data source associated with this application (if any).


destroyInternal

protected void destroyInternal()
Gracefully terminate use of the internal MessageResources.


getApplicationConfig

protected ApplicationConfig getApplicationConfig(javax.servlet.http.HttpServletRequest request)
Deprecated. use getModuleConfig(HttpServletRequest)

Return the module configuration object for the currently selected module.

Parameters:
request - The servlet request we are processing
Since:
Struts 1.1

getModuleConfig

protected ModuleConfig getModuleConfig(javax.servlet.http.HttpServletRequest request)
Return the module configuration object for the currently selected module.

Parameters:
request - The servlet request we are processing
Since:
Struts 1.1

getRequestProcessor

protected RequestProcessor getRequestProcessor(ModuleConfig config)
                                        throws javax.servlet.ServletException
Look up and return the RequestProcessor responsible for the specified module, creating a new one if necessary.

Parameters:
config - The module configuration for which to acquire and return a RequestProcessor.
Throws:
javax.servlet.ServletException - if we cannot instantiate a RequestProcessor instance
Since:
Struts 1.1

initApplicationConfig

protected ApplicationConfig initApplicationConfig(java.lang.String prefix,
                                                  java.lang.String path)
                                           throws javax.servlet.ServletException
Deprecated. use initModuleConfig(String,String)

Initialize the application configuration information for the specified module.

Parameters:
prefix - Module prefix for this module
path - Context-relative resource path for this modules's configuration resource
Throws:
javax.servlet.ServletException - if initialization cannot be performed
Since:
Struts 1.1

initModuleConfig

protected ModuleConfig initModuleConfig(java.lang.String prefix,
                                        java.lang.String paths)
                                 throws javax.servlet.ServletException

Initialize the application configuration information for the specified module.

Parameters:
prefix - Module prefix for this module
paths - Comma-separated list of context-relative resource path(s) for this modules's configuration resource(s)
Throws:
javax.servlet.ServletException - if initialization cannot be performed
Since:
Struts 1.1

parseModuleConfigFile

private void parseModuleConfigFile(java.lang.String prefix,
                                   java.lang.String paths,
                                   ModuleConfig config,
                                   org.apache.commons.digester.Digester digester,
                                   java.lang.String path)
                            throws javax.servlet.UnavailableException
Parses one module config file.

Parameters:
prefix -
paths -
config -
digester - Digester instance that does the parsing
path - The path to the config file to parse.
Throws:
javax.servlet.UnavailableException

handleConfigException

private void handleConfigException(java.lang.String paths,
                                   java.lang.Exception e)
                            throws javax.servlet.UnavailableException
Simplifies exception handling in the parseModuleConfigFile() method.

Parameters:
paths -
e -
Throws:
javax.servlet.UnavailableException

initApplicationDataSources

protected void initApplicationDataSources(ModuleConfig config)
                                   throws javax.servlet.ServletException
Deprecated. use initModuleDataSources(ModuleConfig)

Initialize the data sources for the specified module.

Parameters:
config - ModuleConfig information for this module
Throws:
javax.servlet.ServletException - if initialization cannot be performed
Since:
Struts 1.1

initModuleDataSources

protected void initModuleDataSources(ModuleConfig config)
                              throws javax.servlet.ServletException

Initialize the data sources for the specified module.

Parameters:
config - ModuleConfig information for this module
Throws:
javax.servlet.ServletException - if initialization cannot be performed
Since:
Struts 1.1

initApplicationPlugIns

protected void initApplicationPlugIns(ModuleConfig config)
                               throws javax.servlet.ServletException
Deprecated. use initModulePlugIns(ModuleConfig)

Initialize the plug ins for the specified module.

Parameters:
config - ModuleConfig information for this module
Throws:
javax.servlet.ServletException - if initialization cannot be performed
Since:
Struts 1.1

initModulePlugIns

protected void initModulePlugIns(ModuleConfig config)
                          throws javax.servlet.ServletException

Initialize the plug ins for the specified module.

Parameters:
config - ModuleConfig information for this module
Throws:
javax.servlet.ServletException - if initialization cannot be performed
Since:
Struts 1.1

initApplicationMessageResources

protected void initApplicationMessageResources(ModuleConfig config)
                                        throws javax.servlet.ServletException
Deprecated. use initModuleMessageResources()

Initialize the application MessageResources for the specified module.

Parameters:
config - ModuleConfig information for this module
Throws:
javax.servlet.ServletException - if initialization cannot be performed
Since:
Struts 1.1

initModuleMessageResources

protected void initModuleMessageResources(ModuleConfig config)
                                   throws javax.servlet.ServletException

Initialize the application MessageResources for the specified module.

Parameters:
config - ModuleConfig information for this module
Throws:
javax.servlet.ServletException - if initialization cannot be performed
Since:
Struts 1.1

initConfigDigester

protected org.apache.commons.digester.Digester initConfigDigester()
                                                           throws javax.servlet.ServletException

Create (if needed) and return a new Digester instance that has been initialized to process Struts module configuraiton files and configure a corresponding ModuleConfig object (which must be pushed on to the evaluation stack before parsing begins).

Throws:
javax.servlet.ServletException - if a Digester cannot be configured
Since:
Struts 1.1

initDataSources

protected void initDataSources()
                        throws javax.servlet.ServletException
Deprecated. Replaced by initApplicationDataSources() that takes an ModuleConfig argument. This method does nothing.

Initialize data sources for the default module. This method signature is maintained only for backwards compatibility, and will be removed in a subsequent release.

javax.servlet.ServletException

initInternal

protected void initInternal()
                     throws javax.servlet.ServletException
Initialize our internal MessageResources bundle.

Throws:
javax.servlet.ServletException - if we cannot initialize these resources

initOther

protected void initOther()
                  throws javax.servlet.ServletException
Initialize other global characteristics of the controller servlet.

Throws:
javax.servlet.ServletException - if we cannot initialize these resources

initServlet

protected void initServlet()
                    throws javax.servlet.ServletException
Initialize the servlet mapping under which our controller servlet is being accessed. This will be used in the &html:form> tag to generate correct destination URLs for form submissions.

Throws:
javax.servlet.ServletException - if error happens while scanning web.xml

process

protected void process(javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response)
                throws java.io.IOException,
                       javax.servlet.ServletException
Perform the standard request processing for this request, and create the corresponding response.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet exception is thrown

defaultControllerConfig

private void defaultControllerConfig(ModuleConfig config)
Deprecated. Will be removed in a release after Struts 1.1.

Perform backwards-compatible configuration of the default module's controller configuration from servlet initialization parameters (as were used in Struts 1.0).

Parameters:
config - The ModuleConfig object for the default module
Since:
Struts 1.1

defaultFormBeansConfig

private void defaultFormBeansConfig(ModuleConfig config)
Deprecated. Will be removed in a release after Struts 1.1.

Perform backwards-compatible configuration of an ActionFormBeans collection, and expose it as a servlet context attribute (as was used in Struts 1.0). Note that the current controller code does not (and should not) reference this attribute for any reason.

Parameters:
config - The ModuleConfig object for the default app
Since:
Struts 1.1

defaultForwardsConfig

private void defaultForwardsConfig(ModuleConfig config)
Deprecated. Will be removed in a release after Struts 1.1.

Perform backwards-compatible configuration of an ActionForwards collection, and expose it as a servlet context attribute (as was used in Struts 1.0). Note that the current controller code does not (and should not) reference this attribute for any reason.

Parameters:
config - The ModuleConfig object for the default app
Since:
Struts 1.1

defaultMappingsConfig

private void defaultMappingsConfig(ModuleConfig config)
Deprecated. Will be removed in a release after Struts 1.1.

Perform backwards-compatible configuration of an ActionMappings collection, and expose it as a servlet context attribute (as was used in Struts 1.0). Note that the current controller code does not (and should not) reference this attribute for any reason.

Parameters:
config - The ModuleConfig object for the default app
Since:
Struts 1.1

defaultMessageResourcesConfig

private void defaultMessageResourcesConfig(ModuleConfig config)
Deprecated. Will be removed in a release after Struts 1.1.

Perform backwards-compatible configuration of the default module's message resources configuration from servlet initialization parameters (as were used in Struts 1.0).

Parameters:
config - The ModuleConfig object for the default module
Since:
Struts 1.1


Copyright © 2000-2003 - Apache Software Foundation