org.apache.struts.action

Class ActionServlet

public class ActionServlet extends HttpServlet

ActionServlet provides 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 RequestsProcessor implements the following logic for each incoming HTTP request. You can override some or all of this functionality by subclassing this object 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.

Version: $Rev: 264684 $ $Date: 2005-08-30 04:08:01 +0100 (Tue, 30 Aug 2005) $

Field Summary
protected Stringconfig

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

protected DigesterconfigDigester

The Digester used to produce ModuleConfig objects from a Struts configuration file.

protected booleanconvertNull

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

protected FastHashMapdataSources

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 MessageResourcesinternal

The resources object for our internal resources.

protected StringinternalName

The Java base name of our internal resources.

protected static Loglog

Commons Logging instance.

protected RequestProcessorprocessor

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 StringservletMapping

The URL pattern to which we are mapped in our web application deployment descriptor.

protected StringservletName

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

Method Summary
voidaddRuleSets()

Add any custom RuleSet instances to configDigester that have been specified in the rulesets init parameter.

voidaddServletMapping(String servletName, String urlPattern)

Remember a servlet mapping from our web application deployment descriptor, if it is for this servlet.

voiddestroy()

Gracefully shut down this controller servlet, releasing any resources that were allocated at initialization.

protected voiddestroyConfigDigester()

Gracefully release any configDigester instance that we have created.

protected voiddestroyInternal()

Gracefully terminate use of the internal MessageResources.

protected voiddestroyModules()

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

voiddoGet(HttpServletRequest request, HttpServletResponse response)

Process an HTTP "GET" request.

voiddoPost(HttpServletRequest request, HttpServletResponse response)

Process an HTTP "POST" request.

MessageResourcesgetInternal()

Return the MessageResources instance containing our internal message strings.

protected ModuleConfiggetModuleConfig(HttpServletRequest request)

Return the module configuration object for the currently selected module.

RequestProcessorgetProcessorForModule(ModuleConfig config)

Returns the RequestProcessor for the given module or null if one does not exist.

protected RequestProcessorgetRequestProcessor(ModuleConfig config)

Look up and return the RequestProcessor responsible for the specified module, creating a new one if necessary.

voidhandleConfigException(String path, Exception e)

Simplifies exception handling in the parseModuleConfigFile method.

voidinit()

Initialize this servlet.

protected DigesterinitConfigDigester()

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

protected voidinitInternal()

Initialize our internal MessageResources bundle.

protected ModuleConfiginitModuleConfig(String prefix, String paths)

Initialize the module configuration information for the specified module.

protected voidinitModuleConfigFactory()

Initialize the factory used to create the module configuration.

protected voidinitModuleDataSources(ModuleConfig config)

Initialize the data sources for the specified module.

protected voidinitModuleMessageResources(ModuleConfig config)

Initialize the application MessageResources for the specified module.

protected voidinitModulePlugIns(ModuleConfig config)

Initialize the plug ins for the specified module.

protected voidinitModulePrefixes(ServletContext context)

Saves a String[] of module prefixes in the ServletContext under Globals.MODULE_PREFIXES_KEY.

protected voidinitOther()

Initialize other global characteristics of the controller servlet.

protected voidinitServlet()

Initialize the servlet mapping under which our controller servlet is being accessed.

booleanisValidating()

Check the status of the validating initialization parameter.

protected voidparseModuleConfigFile(Digester digester, String path)

Parses one module config file.

protected voidprocess(HttpServletRequest request, HttpServletResponse response)

Perform the standard request processing for this request, and create the corresponding response.

Field Detail

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.

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.

servletName

protected String servletName

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

Method Detail

addRuleSets

private void addRuleSets()

Add any custom RuleSet instances to configDigester that have been specified in the rulesets init parameter.

Throws: ServletException

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

destroy

public void destroy()

Gracefully shut down this controller servlet, releasing any resources that were allocated at initialization.

destroyConfigDigester

protected void destroyConfigDigester()

Gracefully release any configDigester instance that we have created.

Since: Struts 1.1

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)

Process an HTTP "GET" request.

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

Throws: IOException if an input/output error occurs ServletException if a servlet exception occurs

doPost

public void doPost(HttpServletRequest request, HttpServletResponse response)

Process an HTTP "POST" request.

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

Throws: IOException if an input/output error occurs ServletException if a servlet exception occurs

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

getProcessorForModule

private RequestProcessor getProcessorForModule(ModuleConfig config)

Returns the RequestProcessor for the given module or null if one does not exist. This method will not create a RequestProcessor.

Parameters: config The ModuleConfig.

getRequestProcessor

protected RequestProcessor getRequestProcessor(ModuleConfig config)

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: ServletException if we cannot instantiate a RequestProcessor instance

Since: Struts 1.1

handleConfigException

private void handleConfigException(String path, Exception e)

Simplifies exception handling in the parseModuleConfigFile method.

Parameters: path e

Throws: UnavailableException as a wrapper around Exception

init

public void init()

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.

Throws: ServletException if we cannot configure ourselves correctly

initConfigDigester

protected Digester initConfigDigester()

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

Throws: ServletException if a Digester cannot be configured

Since: Struts 1.1

initInternal

protected void initInternal()

Initialize our internal MessageResources bundle.

Throws: ServletException if we cannot initialize these resources

initModuleConfig

protected ModuleConfig initModuleConfig(String prefix, String paths)

Initialize the module 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: ServletException if initialization cannot be performed

Since: Struts 1.1

initModuleConfigFactory

protected void initModuleConfigFactory()

Initialize the factory used to create the module configuration.

Since: Struts 1.2

initModuleDataSources

protected void initModuleDataSources(ModuleConfig config)

Initialize the data sources for the specified module.

Parameters: config ModuleConfig information for this module

Throws: ServletException if initialization cannot be performed

Since: Struts 1.1

initModuleMessageResources

protected void initModuleMessageResources(ModuleConfig config)

Initialize the application MessageResources for the specified module.

Parameters: config ModuleConfig information for this module

Throws: ServletException if initialization cannot be performed

Since: Struts 1.1

initModulePlugIns

protected void initModulePlugIns(ModuleConfig config)

Initialize the plug ins for the specified module.

Parameters: config ModuleConfig information for this module

Throws: ServletException if initialization cannot be performed

Since: Struts 1.1

initModulePrefixes

protected void initModulePrefixes(ServletContext context)

Saves a String[] of module prefixes in the ServletContext under Globals.MODULE_PREFIXES_KEY. NOTE - the "" prefix for the default module is not included in this list.

Parameters: context The servlet context.

Since: Struts 1.2

initOther

protected void initOther()

Initialize other global characteristics of the controller servlet.

Throws: ServletException if we cannot initialize these resources

initServlet

protected void initServlet()

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: ServletException if error happens while scanning web.xml

isValidating

private boolean isValidating()

Check the status of the validating initialization parameter.

Returns: true if the module Digester should validate.

parseModuleConfigFile

protected void parseModuleConfigFile(Digester digester, String path)

Parses one module config file.

Parameters: digester Digester instance that does the parsing path The path to the config file to parse.

Throws: UnavailableException if file cannot be read or parsed

Since: Struts 1.2

process

protected void process(HttpServletRequest request, HttpServletResponse response)

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: IOException if an input/output error occurs ServletException if a servlet exception is thrown

Copyright B) 2000-2009 - The Apache Software Foundation