|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet org.apache.struts.action.ActionServlet
public class ActionServlet
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:
RequestProcessor
object. This component represents the "controller"
component of an MVC architecture. RequestProcessor
selects and invokes an Action
class to perform the requested business logic, or delegates the response to
another resource.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.Action
classes generally return an ActionForward
to
indicate which resource should handle the response. If the
Action
does not return null, the RequestProcessor
forwards or redirects to the specified resource (by utilizing
RequestDispatcher.forward
or Response.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.
Action
interface).
Action
class, instantiate an instance of that class and cache it for future
use.ActionForm
bean
associated with this mapping.execute
method of this Action
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.
ModuleConfigFactory
used to create the implementation of the
ModuleConfig interface. java.lang.Integer
) will default to null
(rather than 0). (Since Struts 1.1) [false] org.apache.commons.digester.RuleSet
instances that should be added to the Digester
that will be
processing struts-config.xml
files. By default, only the
RuleSet
for the standard configuration elements is loaded.
(Since Struts 1.1)
Field Summary | |
---|---|
protected java.lang.String |
chainConfig
Comma-separated list of context or classloader-relative path(s) that contain the configuration for the default commons-chain catalog(s). |
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 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 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. |
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. |
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. |
protected RequestProcessor |
getRequestProcessor(ModuleConfig config)
Look up and return the RequestProcessor responsible for the
specified module, creating a new one if necessary. |
void |
init()
Initialize this servlet. |
protected void |
initChain()
Parse the configuration documents specified by the chainConfig init-param to configure the default Catalog that is registered in the CatalogFactory instance for this application. |
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 void |
initModuleActions(ModuleConfig config)
Initialize the action configs for the specified module. |
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 |
initModuleExceptionConfigs(ModuleConfig config)
Initialize the exception handlers for the specified module. |
protected void |
initModuleFormBeans(ModuleConfig config)
Initialize the form beans for the specified module. |
protected void |
initModuleForwards(ModuleConfig config)
Initialize the forwards 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. |
protected void |
parseModuleConfigFile(org.apache.commons.digester.Digester digester,
java.lang.String path)
Deprecated. use parseModuleConfigFile(Digester digester, URL url) instead |
protected void |
parseModuleConfigFile(org.apache.commons.digester.Digester digester,
java.net.URL url)
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. |
protected ActionConfig |
processActionConfigClass(ActionConfig actionConfig,
ModuleConfig moduleConfig)
Checks if the current actionConfig is using the correct class based on the class of its ancestor ActionConfig. |
protected void |
processActionConfigExtension(ActionConfig actionConfig,
ModuleConfig moduleConfig)
Extend the action's configuration as necessary. |
protected ExceptionConfig |
processExceptionConfigClass(ExceptionConfig exceptionConfig,
ModuleConfig moduleConfig,
ActionConfig actionConfig)
Checks if the current exceptionConfig is using the correct class based on the class of its configuration ancestor. |
protected void |
processExceptionExtension(ExceptionConfig exceptionConfig,
ModuleConfig moduleConfig,
ActionConfig actionConfig)
Extend the exception's configuration as necessary. |
protected FormBeanConfig |
processFormBeanConfigClass(FormBeanConfig beanConfig,
ModuleConfig moduleConfig)
Checks if the current beanConfig is using the correct class based on the class of its ancestor form bean config. |
protected void |
processFormBeanExtension(FormBeanConfig beanConfig,
ModuleConfig moduleConfig)
Extend the form bean's configuration as necessary. |
protected ForwardConfig |
processForwardConfigClass(ForwardConfig forwardConfig,
ModuleConfig moduleConfig,
ActionConfig actionConfig)
Checks if the current forwardConfig is using the correct class based on the class of its configuration ancestor. |
protected void |
processForwardExtension(ForwardConfig forwardConfig,
ModuleConfig moduleConfig,
ActionConfig actionConfig)
Extend the forward's configuration as necessary. |
protected java.util.List |
splitAndResolvePaths(java.lang.String paths)
Takes a comma-delimited string and splits it into paths, then resolves those paths using the ServletContext and appropriate ClassLoader. |
Methods inherited from class javax.servlet.http.HttpServlet |
---|
doDelete, doHead, 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 |
---|
protected static org.apache.commons.logging.Log log
Commons Logging instance.
protected java.lang.String config
Comma-separated list of context-relative path(s) to our configuration resource(s) for the default module.
protected java.lang.String chainConfig
Comma-separated list of context or classloader-relative path(s) that contain the configuration for the default commons-chain catalog(s).
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 MessageResources internal
The resources object for our internal resources.
protected java.lang.String internalName
The Java base name of our internal resources.
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!
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.
Constructor Detail |
---|
public ActionServlet()
Method Detail |
---|
public void destroy()
Gracefully shut down this controller servlet, releasing any resources that were allocated at initialization.
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
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.
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
- if we cannot configure ourselves correctlyprotected 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.
context
- The servlet context.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.
doGet
in class javax.servlet.http.HttpServlet
request
- The servlet request we are processingresponse
- The servlet response we are creating
java.io.IOException
- if an input/output error occurs
javax.servlet.ServletException
- if a servlet exception occurspublic void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
Process an HTTP "POST" request.
doPost
in class javax.servlet.http.HttpServlet
request
- The servlet request we are processingresponse
- The servlet response we are creating
java.io.IOException
- if an input/output error occurs
javax.servlet.ServletException
- if a servlet exception occurspublic 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.
servletName
- The name of the servlet being mappedurlPattern
- The URL pattern to which this servlet is mappedpublic MessageResources getInternal()
Return the MessageResources
instance containing our
internal message strings.
MessageResources
instance containing our
internal message strings.protected void destroyModules()
Gracefully terminate use of any modules associated with this application (if any).
protected void destroyConfigDigester()
Gracefully release any configDigester instance that we have created.
protected void destroyInternal()
Gracefully terminate use of the internal MessageResources.
protected ModuleConfig getModuleConfig(javax.servlet.http.HttpServletRequest request)
Return the module configuration object for the currently selected module.
request
- The servlet request we are processing
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.
config
- The module configuration for which to acquire and return
a RequestProcessor.
RequestProcessor
responsible for the specified
module,
javax.servlet.ServletException
- If we cannot instantiate a RequestProcessor
instance a UnavailableException
is
thrown, meaning your application is not loaded
and will not be available.protected void initModuleConfigFactory()
Initialize the factory used to create the module configuration.
protected ModuleConfig initModuleConfig(java.lang.String prefix, java.lang.String paths) throws javax.servlet.ServletException
Initialize the module configuration information for the specified module.
prefix
- Module prefix for this modulepaths
- Comma-separated list of context-relative resource path(s)
for this modules's configuration resource(s)
javax.servlet.ServletException
- if initialization cannot be performedprotected void parseModuleConfigFile(org.apache.commons.digester.Digester digester, java.lang.String path) throws javax.servlet.UnavailableException
Parses one module config file.
digester
- Digester instance that does the parsingpath
- The path to the config file to parse.
javax.servlet.UnavailableException
- if file cannot be read or parsedprotected void parseModuleConfigFile(org.apache.commons.digester.Digester digester, java.net.URL url) throws javax.servlet.UnavailableException
Parses one module config file.
digester
- Digester instance that does the parsingurl
- The url to the config file to parse.
javax.servlet.UnavailableException
- if file cannot be read or parsedprotected void initModulePlugIns(ModuleConfig config) throws javax.servlet.ServletException
Initialize the plug ins for the specified module.
config
- ModuleConfig information for this module
javax.servlet.ServletException
- if initialization cannot be performedprotected void initModuleFormBeans(ModuleConfig config) throws javax.servlet.ServletException
Initialize the form beans for the specified module.
config
- ModuleConfig information for this module
javax.servlet.ServletException
- if initialization cannot be performedprotected void processFormBeanExtension(FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws javax.servlet.ServletException
Extend the form bean's configuration as necessary.
beanConfig
- the configuration to process.moduleConfig
- the module configuration for this module.
javax.servlet.ServletException
- if initialization cannot be performed.protected FormBeanConfig processFormBeanConfigClass(FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws javax.servlet.ServletException
Checks if the current beanConfig is using the correct class based on the class of its ancestor form bean config.
beanConfig
- The form bean to check.moduleConfig
- The config for the current module.
javax.servlet.UnavailableException
- if an instance of the form bean config
class cannot be created.
javax.servlet.ServletException
- on class creation errorprotected void initModuleForwards(ModuleConfig config) throws javax.servlet.ServletException
Initialize the forwards for the specified module.
config
- ModuleConfig information for this module
javax.servlet.ServletException
- if initialization cannot be performedprotected void processForwardExtension(ForwardConfig forwardConfig, ModuleConfig moduleConfig, ActionConfig actionConfig) throws javax.servlet.ServletException
Extend the forward's configuration as necessary. If actionConfig is provided, then this method will process the forwardConfig as part of that actionConfig. If actionConfig is null, the forwardConfig will be processed as a global forward.
forwardConfig
- the configuration to process.moduleConfig
- the module configuration for this module.actionConfig
- If applicable, the config for the current action.
javax.servlet.ServletException
- if initialization cannot be performed.protected ForwardConfig processForwardConfigClass(ForwardConfig forwardConfig, ModuleConfig moduleConfig, ActionConfig actionConfig) throws javax.servlet.ServletException
Checks if the current forwardConfig is using the correct class based on the class of its configuration ancestor. If actionConfig is provided, then this method will process the forwardConfig as part of that actionConfig. If actionConfig is null, the forwardConfig will be processed as a global forward.
forwardConfig
- The forward to check.moduleConfig
- The config for the current module.actionConfig
- If applicable, the config for the current action.
javax.servlet.UnavailableException
- if an instance of the forward config class
cannot be created.
javax.servlet.ServletException
- on class creation errorprotected void initModuleExceptionConfigs(ModuleConfig config) throws javax.servlet.ServletException
Initialize the exception handlers for the specified module.
config
- ModuleConfig information for this module
javax.servlet.ServletException
- if initialization cannot be performedprotected void processExceptionExtension(ExceptionConfig exceptionConfig, ModuleConfig moduleConfig, ActionConfig actionConfig) throws javax.servlet.ServletException
Extend the exception's configuration as necessary. If actionConfig is provided, then this method will process the exceptionConfig as part of that actionConfig. If actionConfig is null, the exceptionConfig will be processed as a global forward.
exceptionConfig
- the configuration to process.moduleConfig
- the module configuration for this module.actionConfig
- If applicable, the config for the current action.
javax.servlet.ServletException
- if initialization cannot be performed.protected ExceptionConfig processExceptionConfigClass(ExceptionConfig exceptionConfig, ModuleConfig moduleConfig, ActionConfig actionConfig) throws javax.servlet.ServletException
Checks if the current exceptionConfig is using the correct class based on the class of its configuration ancestor. If actionConfig is provided, then this method will process the exceptionConfig as part of that actionConfig. If actionConfig is null, the exceptionConfig will be processed as a global forward.
exceptionConfig
- The config to check.moduleConfig
- The config for the current module.actionConfig
- If applicable, the config for the current action.
javax.servlet.ServletException
- if an instance of the exception config class
cannot be created.protected void initModuleActions(ModuleConfig config) throws javax.servlet.ServletException
Initialize the action configs for the specified module.
config
- ModuleConfig information for this module
javax.servlet.ServletException
- if initialization cannot be performedprotected void processActionConfigExtension(ActionConfig actionConfig, ModuleConfig moduleConfig) throws javax.servlet.ServletException
Extend the action's configuration as necessary.
actionConfig
- the configuration to process.moduleConfig
- the module configuration for this module.
javax.servlet.ServletException
- if initialization cannot be performed.protected ActionConfig processActionConfigClass(ActionConfig actionConfig, ModuleConfig moduleConfig) throws javax.servlet.ServletException
Checks if the current actionConfig is using the correct class based on the class of its ancestor ActionConfig.
actionConfig
- The action config to check.moduleConfig
- The config for the current module.
javax.servlet.ServletException
- if an instance of the action config class
cannot be created.protected void initModuleMessageResources(ModuleConfig config) throws javax.servlet.ServletException
Initialize the application MessageResources
for the
specified module.
config
- ModuleConfig information for this module
javax.servlet.ServletException
- if initialization cannot be performedprotected 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 corresponding ModuleConfig
object (which
must be pushed on to the evaluation stack before parsing begins).
Digester
instance.
javax.servlet.ServletException
- if a Digester cannot be configuredprotected void initInternal() throws javax.servlet.ServletException
Initialize our internal MessageResources bundle.
javax.servlet.ServletException
- if we cannot initialize these resources
javax.servlet.UnavailableException
- if we cannot load resourcesprotected void initChain() throws javax.servlet.ServletException
Parse the configuration documents specified by the
chainConfig
init-param to configure the default Catalog
that is registered in the CatalogFactory
instance for this application.
javax.servlet.ServletException
- if an error occurs.protected void initOther() throws javax.servlet.ServletException
Initialize other global characteristics of the controller servlet.
javax.servlet.ServletException
- if we cannot initialize these resourcesprotected 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.
javax.servlet.ServletException
- if error happens while scanning web.xmlprotected java.util.List splitAndResolvePaths(java.lang.String paths) throws javax.servlet.ServletException
Takes a comma-delimited string and splits it into paths, then resolves those paths using the ServletContext and appropriate ClassLoader. When loading from the classloader, multiple resources per path are supported to support, for example, multiple jars containing the same named config file.
paths
- A comma-delimited string of paths
javax.servlet.ServletException
- if a servlet exception is thrownprotected 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.
request
- The servlet request we are processingresponse
- The servlet response we are creating
java.io.IOException
- if an input/output error occurs
javax.servlet.ServletException
- if a servlet exception is thrown
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |