org.apache.struts.action

Class ActionServlet

Known Direct Subclasses:
ActionComponentServlet

public class ActionServlet
extends 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.

DEPRECATED - Configure this using the "className" attribute of each <forward> element.
  • locale - If set to true, and there is a user session, identify and store an appropriate java.util.Locale object (under the standard key identified by Globals.LOCALE_KEY) in the user's session if there is not a Locale object there already. [true] DEPRECATED - Configure this using the "locale" attribute of the <controller> element.
  • mapping - The Java class name of the ActionMapping implementation to use [org.apache.struts.action.ActionMapping]. Two convenient classes you may wish to use are: DEPRECATED - Configure this using the "className" attribute of each <action> element, or globally for a module by using the "type" attribute of the <action-mappings> element.
  • maxFileSize - The maximum size (in bytes) of a file to be accepted as a file upload. Can be expressed as a number followed by a "K" "M", or "G", which are interpreted to mean kilobytes, megabytes, or gigabytes, respectively. [250M] DEPRECATED - Configure this using the "maxFileSize" attribute of the <controller> element.
  • multipartClass - The fully qualified name of the MultipartRequestHandler implementation class to be used for processing file uploads. If set to none, disables Struts multipart request handling. [org.apache.struts.upload.CommonsMultipartRequestHandler] DEPRECATED - Configure this using the "multipartClass" attribute of the <controller> element.
  • nocache - If set to true, add HTTP headers to every response intended to defeat browser caching of any response we generate or forward to. [false] DEPRECATED - Configure this using the "nocache" attribute of the <controller> element.
  • null - If set to true, set our application resources to return null if an unknown message key is used. Otherwise, an error message including the offending message key will be returned. [true] DEPRECATED - Configure this using the "null" attribute of the <message-resources> element.
  • tempDir - The temporary working directory to use when processing file uploads. [The working directory provided to this web application as a servlet context attribute] DEPRECATED - Configure this using the "tempDir" attribute of the <controller> element.
  • Version:
    $Revision: 1.150 $ $Date: 2003/06/28 06:16:34 $

    Authors:
    Craig R. McClanahan
    Ted Husted
    Martin Cooper
    David Graham

    Field Summary

    protected String
    config
    Comma-separated list of context-relative path(s) to our configuration resource(s) for the default module.
    protected 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 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 String
    internalName
    The Java base name of our internal resources.
    protected static Log
    log
    Commons Logging instance.
    protected RequestProcessor
    processor
    The RequestProcessor instance we will use to process all incoming requests.
    protected String[]
    registrations
    The set of public identifiers, and corresponding resource names, for the versions of the configuration file DTDs that we know about.
    protected String
    servletMapping
    The URL pattern to which we are mapped in our web application deployment descriptor.
    protected String
    servletName
    The servlet name under which we are registered in our web application deployment descriptor.

    Method Summary

    void
    addServletMapping(String servletName, 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(HttpServletRequest request, HttpServletResponse response)
    Process an HTTP "GET" request.
    void
    doPost(HttpServletRequest request, HttpServletResponse response)
    Process an HTTP "POST" request.
    DataSource
    findDataSource(String key)
    Deprecated. Look up data sources directly in servlet context attributes
    ActionFormBean
    findFormBean(String name)
    Deprecated. Replaced by ModuleConfig.findFormBeanConfig()
    ActionForward
    findForward(String name)
    Deprecated. Replaced by ModuleConfig.findForwardConfig()
    ActionMapping
    findMapping(String path)
    Deprecated. Replaced by ModuleConfig.findActionConfig()
    protected ApplicationConfig
    getApplicationConfig(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(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(String paths, Exception e)
    Simplifies exception handling in the parseModuleConfigFile() method.
    void
    init()
    Initialize this servlet.
    protected ApplicationConfig
    initApplicationConfig(String prefix, 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 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.
    protected void
    initInternal()
    Initialize our internal MessageResources bundle.
    protected ModuleConfig
    initModuleConfig(String prefix, 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(String message, int level)
    Deprecated. Use commons-logging instead.
    private void
    parseModuleConfigFile(String prefix, String paths, ModuleConfig config, Digester digester, String path)
    Parses one module config file.
    protected void
    process(HttpServletRequest request, HttpServletResponse response)
    Perform the standard request processing for this request, and create the corresponding response.

    Field Details

    config

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


    configDigester

    protected 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 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 String internalName
    The Java base name of our internal resources.

    Since:
    Struts 1.1


    log

    protected static 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 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 String servletMapping
    The URL pattern to which we are mapped in our web application deployment descriptor. FIXME - multiples???


    servletName

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

    Method Details

    addServletMapping

    public void addServletMapping(String servletName,
                                  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


    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


    destroy

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


    destroyApplications

    protected void destroyApplications()

    Deprecated. replaced by 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.


    destroyModules

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

    Since:
    Struts 1.1


    doGet

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
                throws IOException,
                       ServletException
    Process an HTTP "GET" request.

    Parameters:
    request - The servlet request we are processing
    response - The servlet response we are creating


    doPost

    public void doPost(HttpServletRequest request,
                       HttpServletResponse response)
                throws IOException,
                       ServletException
    Process an HTTP "POST" request.

    Parameters:
    request - The servlet request we are processing
    response - The servlet response we are creating


    findDataSource

    public DataSource findDataSource(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(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(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(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


    getApplicationConfig

    protected ApplicationConfig getApplicationConfig(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


    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


    getModuleConfig

    protected ModuleConfig getModuleConfig(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 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.

    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.


    handleConfigException

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

    Parameters:
    paths -
    e -


    init

    public void init()
                throws 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.


    initApplicationConfig

    protected ApplicationConfig initApplicationConfig(String prefix,
                                                      String path)
                throws 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

    Since:
    Struts 1.1


    initApplicationDataSources

    protected void initApplicationDataSources(ModuleConfig config)
                throws ServletException

    Deprecated. use initModuleDataSources(ModuleConfig)

    Initialize the data sources for the specified module.

    Parameters:
    config - ModuleConfig information for this module

    Since:
    Struts 1.1


    initApplicationMessageResources

    protected void initApplicationMessageResources(ModuleConfig config)
                throws ServletException

    Deprecated. use initModuleMessageResources()

    Initialize the application MessageResources for the specified module.

    Parameters:
    config - ModuleConfig information for this module

    Since:
    Struts 1.1


    initApplicationPlugIns

    protected void initApplicationPlugIns(ModuleConfig config)
                throws ServletException

    Deprecated. use initModulePlugIns(ModuleConfig)

    Initialize the plug ins for the specified module.

    Parameters:
    config - ModuleConfig information for this module

    Since:
    Struts 1.1


    initConfigDigester

    protected Digester initConfigDigester()
                throws 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).

    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.


    initInternal

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


    initModuleConfig

    protected ModuleConfig initModuleConfig(String prefix,
                                            String paths)
                throws 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)

    Since:
    Struts 1.1


    initModuleDataSources

    protected void initModuleDataSources(ModuleConfig config)
                throws ServletException
    Initialize the data sources for the specified module.

    Parameters:
    config - ModuleConfig information for this module

    Since:
    Struts 1.1


    initModuleMessageResources

    protected void initModuleMessageResources(ModuleConfig config)
                throws ServletException
    Initialize the application MessageResources for the specified module.

    Parameters:
    config - ModuleConfig information for this module

    Since:
    Struts 1.1


    initModulePlugIns

    protected void initModulePlugIns(ModuleConfig config)
                throws ServletException
    Initialize the plug ins for the specified module.

    Parameters:
    config - ModuleConfig information for this module

    Since:
    Struts 1.1


    initOther

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


    initServlet

    protected void initServlet()
                throws 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.


    log

    public void log(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


    parseModuleConfigFile

    private void parseModuleConfigFile(String prefix,
                                       String paths,
                                       ModuleConfig config,
                                       Digester digester,
                                       String path)
                throws 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.


    process

    protected void process(HttpServletRequest request,
                           HttpServletResponse response)
                throws IOException,
                       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


    Copyright B) 2000-2005 - Apache Software Foundation