|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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:
- RedeployableActionServlet
- public class ActionServlet
- extends javax.servlet.http.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 user interface will generally be created with server pages, which will not themselves contain any business logic. These pages represent the "view" component of an MVC architecture.
- Forms and hyperlinks in the user interface that require business logic to be executed will be submitted to a request URI that is mapped to this servlet.
- There can be one instance of this servlet class,
which receives and processes all requests that change the state of
a user's interaction with the application. The servlet delegates the
handling of a request to a
RequestProcessor
object. This component represents the "controller" component of an MVC architecture. - The
RequestProcessor
selects and invokes anAction
class to perform the requested business logic, or delegates the response to another resource. - The
Action
classes can manipulate the state of the application's interaction with the user, typically by creating or modifying JavaBeans that are stored as request or session attributes (depending on how long they need to be available). Such JavaBeans represent the "model" component of an MVC architecture. - Instead of producing the next page of the user interface directly,
Action
classes generally return anActionForward
to indicate which resource should handle the response. If theAction
does not return null, theRequestProcessor
forwards or redirects to the specified resource (by utilizingRequestDispatcher.forward
orResponse.sendRedirect
) so as to produce the next page of the user interface.
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.
- Identify, from the incoming request URI, the substring that will be used to select an action procedure.
- Use this substring to map to the Java class name of the corresponding
action class (an implementation of the
Action
interface). - If this is the first request for a particular
Action
class, instantiate an instance of that class and cache it for future use. - Optionally populate the properties of an
ActionForm
bean associated with this mapping. - Call the
execute
method of thisAction
class, passing on a reference to the mapping that was used, the relevant form-bean (if any), and the request and the response that were passed to the controller by the servlet container (thereby providing access to any specialized properties of the mapping itself as well as to the ServletContext).
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.
- config - Comma-separated list of context-relative path(s) to the XML resource(s) containing the configuration information for the default module. (Multiple files support since Struts 1.1) [/WEB-INF/struts-config.xml].
- config/${module} - Comma-separated list of Context-relative path(s) to the XML resource(s) containing the configuration information for the module that will use the specified prefix (/${module}). This can be repeated as many times as required for multiple modules. (Since Struts 1.1)
- configFactory - The Java class name of the
ModuleConfigFactory
used to create the implementation of theModuleConfig
interface. [org.apache.struts.config.impl.DefaultModuleConfigFactory] - convertNull - Force simulation of the Struts 1.0 behavior
when populating forms. If set to true, the numeric Java wrapper class types
(like
java.lang.Integer
) will default to null (rather than 0). (Since Struts 1.1) [false] - rulesets - Comma-delimited list of fully qualified
classnames of additional
org.apache.commons.digester.RuleSet
instances that should be added to theDigester
that will be processingstruts-config.xml
files. By default, only theRuleSet
for the standard configuration elements is loaded. (Since Struts 1.1) - validating - Should we use a validating XML parser to process the configuration file (strongly recommended)? [true]
- Version:
- $Rev: 164530 $ $Date: 2005-04-25 04:11:07 +0100 (Mon, 25 Apr 2005) $
- 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 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 |
HEADER_IFMODSINCE, HEADER_LASTMOD, LSTRING_FILE, lStrings, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_POST, METHOD_PUT, METHOD_TRACE |
Constructor Summary | |
ActionServlet()
|
Method Summary | |
private void |
addRuleSets()
Add any custom RuleSet instances to configDigester that have been specified in the rulesets init parameter. |
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. |
void |
destroy()
Gracefully shut down this controller servlet, releasing any resources that were allocated at initialization. |
protected void |
destroyConfigDigester()
Gracefully release any configDigester instance that we have created. |
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. |
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. |
private RequestProcessor |
getProcessorForModule(ModuleConfig config)
Returns the RequestProcessor for the given module or null if one does not exist. |
protected RequestProcessor |
getRequestProcessor(ModuleConfig config)
Look up and return the RequestProcessor responsible for the
specified module, creating a new one if necessary. |
private void |
handleConfigException(java.lang.String path,
java.lang.Exception e)
Simplifies exception handling in the parseModuleConfigFile method. |
void |
init()
Initialize this servlet. |
protected org.apache.commons.digester.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). |
protected void |
initInternal()
Initialize our internal MessageResources bundle. |
protected ModuleConfig |
initModuleConfig(java.lang.String prefix,
java.lang.String paths)
Initialize the module configuration information for the specified module. |
protected void |
initModuleConfigFactory()
Initialize the factory used to create the module configuration. |
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 |
initModulePrefixes(javax.servlet.ServletContext context)
Saves a String[] of module prefixes in the ServletContext under Globals.MODULE_PREFIXES_KEY. |
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. |
private boolean |
isValidating()
Check the status of the validating initialization parameter. |
protected void |
parseModuleConfigFile(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 |
|
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, registerNatives, 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.
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.
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.
- Overrides:
destroy
in classjavax.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 classjavax.servlet.GenericServlet
- Throws:
javax.servlet.ServletException
- if we cannot configure ourselves correctly
initModulePrefixes
protected void initModulePrefixes(javax.servlet.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
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 classjavax.servlet.http.HttpServlet
- Parameters:
request
- The servlet request we are processingresponse
- The servlet response we are creating- Throws:
java.io.IOException
- if an input/output error occursjavax.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 classjavax.servlet.http.HttpServlet
- Parameters:
request
- The servlet request we are processingresponse
- The servlet response we are creating- Throws:
java.io.IOException
- if an input/output error occursjavax.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 mappedurlPattern
- The URL pattern to which this servlet is mapped
getInternal
public MessageResources getInternal()
Return the
MessageResources
instance containing our internal message strings.- 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
destroyInternal
protected void destroyInternal()
Gracefully terminate use of the internal MessageResources.
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
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.
initModuleConfigFactory
protected void initModuleConfigFactory()
Initialize the factory used to create the module configuration.
- Since:
- Struts 1.2
initModuleConfig
protected ModuleConfig initModuleConfig(java.lang.String prefix, java.lang.String paths) throws javax.servlet.ServletException
Initialize the module configuration information for the specified module.
- Parameters:
prefix
- Module prefix for this modulepaths
- 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
protected void parseModuleConfigFile(org.apache.commons.digester.Digester digester, java.lang.String path) throws javax.servlet.UnavailableException
Parses one module config file.
- Parameters:
digester
- Digester instance that does the parsingpath
- The path to the config file to parse.- Throws:
javax.servlet.UnavailableException
- if file cannot be read or parsed- Since:
- Struts 1.2
handleConfigException
private void handleConfigException(java.lang.String path, java.lang.Exception e) throws javax.servlet.UnavailableException
Simplifies exception handling in the
parseModuleConfigFile
method.- Parameters:
path
-e
-- Throws:
javax.servlet.UnavailableException
- as a wrapper around Exception
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
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
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 configuration files and configure a correspondingModuleConfig
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
addRuleSets
private void addRuleSets() throws javax.servlet.ServletException
Add any custom RuleSet instances to configDigester that have been specified in the
rulesets
init parameter.- Throws:
javax.servlet.ServletException
-
isValidating
private boolean isValidating()
Check the status of the
validating
initialization parameter.- Returns:
- true if the module Digester should validate.
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 processingresponse
- The servlet response we are creating- Throws:
java.io.IOException
- if an input/output error occursjavax.servlet.ServletException
- if a servlet exception is thrown
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright � 2000-2005 - The Apache Software Foundation