org.apache.struts2.dispatcher
类 Dispatcher

java.lang.Object
  继承者 org.apache.struts2.dispatcher.Dispatcher

public class Dispatcher
extends Object

A utility class the actual dispatcher delegates most of its tasks to. Each instance of the primary dispatcher holds an instance of this dispatcher to be shared for all requests.

另请参见:
FilterDispatcher

嵌套类摘要
static class Dispatcher.Locator
          Provide an accessor class for static XWork utility.
 
构造方法摘要
Dispatcher(javax.servlet.ServletContext servletContext, Map<String,String> initParams)
          Create the Dispatcher instance for a given ServletContext and set of initialization parameters.
 
方法摘要
static void addDispatcherListener(DispatcherListener listener)
          Add a dispatcher lifecycle listener.
 void cleanup()
          Releases all instances bound to this dispatcher instance.
 void cleanUpAfterInit()
          Cleanup any resources used to initialise Dispatcher
 void cleanUpRequest(javax.servlet.http.HttpServletRequest request)
          Removes all the files created by MultiPartRequestWrapper.
 Map<String,Object> createContextMap(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMapping mapping, javax.servlet.ServletContext context)
          Create a context map containing all the wrapped request objects
 HashMap<String,Object> createContextMap(Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext servletContext)
          Merge all application and servlet attributes into a single HashMap to represent the entire Action context.
 com.opensymphony.xwork2.config.ConfigurationManager getConfigurationManager()
          Expose the ConfigurationManager instance.
 com.opensymphony.xwork2.inject.Container getContainer()
          Expose the dependency injection container.
static Dispatcher getInstance()
          Provide the dispatcher instance for the current thread.
 void init()
          Load configurations, including both XML and zero-configuration strategies, and update optional settings, including whether to reload configurations and resource files.
 void prepare(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Prepare a request, including setting the encoding and locale.
static void removeDispatcherListener(DispatcherListener listener)
          Remove a specific dispatcher lifecycle listener.
 void sendError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext ctx, int code, Exception e)
          Send an HTTP error response code.
 void serviceAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext context, ActionMapping mapping)
          Load Action class for mapping and invoke the appropriate Action method, or go directly to the Result.
 void setConfigurationManager(com.opensymphony.xwork2.config.ConfigurationManager mgr)
          已过时。 should be removed as is used only in tests
 void setDefaultEncoding(String val)
          Modify state of StrutsConstants.STRUTS_I18N_ENCODING setting.
 void setDefaultLocale(String val)
          Modify state of StrutsConstants.STRUTS_LOCALE setting.
 void setDevMode(String mode)
          Modify state of StrutsConstants.STRUTS_DEVMODE setting.
 void setDisableRequestAttributeValueStackLookup(String disableRequestAttributeValueStackLookup)
          Modify state of StrutsConstants.DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP setting.
 void setHandleException(String handleException)
           
static void setInstance(Dispatcher instance)
          Store the dispatcher instance for this thread.
 void setMultipartHandler(String val)
           
 void setMultipartSaveDir(String val)
          Modify state of StrutsConstants.STRUTS_MULTIPART_SAVEDIR setting.
 void setValueStackFactory(com.opensymphony.xwork2.util.ValueStackFactory valueStackFactory)
           
 javax.servlet.http.HttpServletRequest wrapRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext servletContext)
          Wrap and return the given request or return the original request object.
 
从类 java.lang.Object 继承的方法
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

Dispatcher

public Dispatcher(javax.servlet.ServletContext servletContext,
                  Map<String,String> initParams)
Create the Dispatcher instance for a given ServletContext and set of initialization parameters.

参数:
servletContext - Our servlet context
initParams - The set of initialization parameters
方法详细信息

getInstance

public static Dispatcher getInstance()
Provide the dispatcher instance for the current thread.

返回:
The dispatcher instance

setInstance

public static void setInstance(Dispatcher instance)
Store the dispatcher instance for this thread.

参数:
instance - The instance

addDispatcherListener

public static void addDispatcherListener(DispatcherListener listener)
Add a dispatcher lifecycle listener.

参数:
listener - The listener to add

removeDispatcherListener

public static void removeDispatcherListener(DispatcherListener listener)
Remove a specific dispatcher lifecycle listener.

参数:
listener - The listener

setDevMode

public void setDevMode(String mode)
Modify state of StrutsConstants.STRUTS_DEVMODE setting.

参数:
mode - New setting

setDisableRequestAttributeValueStackLookup

public void setDisableRequestAttributeValueStackLookup(String disableRequestAttributeValueStackLookup)
Modify state of StrutsConstants.DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP setting.

参数:
disableRequestAttributeValueStackLookup - New setting

setDefaultLocale

public void setDefaultLocale(String val)
Modify state of StrutsConstants.STRUTS_LOCALE setting.

参数:
val - New setting

setDefaultEncoding

public void setDefaultEncoding(String val)
Modify state of StrutsConstants.STRUTS_I18N_ENCODING setting.

参数:
val - New setting

setMultipartSaveDir

public void setMultipartSaveDir(String val)
Modify state of StrutsConstants.STRUTS_MULTIPART_SAVEDIR setting.

参数:
val - New setting

setMultipartHandler

public void setMultipartHandler(String val)

setValueStackFactory

public void setValueStackFactory(com.opensymphony.xwork2.util.ValueStackFactory valueStackFactory)

setHandleException

public void setHandleException(String handleException)

cleanup

public void cleanup()
Releases all instances bound to this dispatcher instance.


init

public void init()
Load configurations, including both XML and zero-configuration strategies, and update optional settings, including whether to reload configurations and resource files.


serviceAction

public void serviceAction(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response,
                          javax.servlet.ServletContext context,
                          ActionMapping mapping)
                   throws javax.servlet.ServletException
Load Action class for mapping and invoke the appropriate Action method, or go directly to the Result.

This method first creates the action context from the given parameters, and then loads an ActionProxy from the given action name and namespace. After that, the Action method is executed and output channels through the response object. Actions not found are sent back to the user via the sendError(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext, int, java.lang.Exception) method, using the 404 return code. All other errors are reported by throwing a ServletException.

参数:
request - the HttpServletRequest object
response - the HttpServletResponse object
mapping - the action mapping object
context - Our ServletContext object
抛出:
javax.servlet.ServletException - when an unknown error occurs (not a 404, but typically something that would end up as a 5xx by the servlet container)

createContextMap

public Map<String,Object> createContextMap(javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpServletResponse response,
                                           ActionMapping mapping,
                                           javax.servlet.ServletContext context)
Create a context map containing all the wrapped request objects

参数:
request - The servlet request
response - The servlet response
mapping - The action mapping
context - The servlet context
返回:
A map of context objects

createContextMap

public HashMap<String,Object> createContextMap(Map requestMap,
                                               Map parameterMap,
                                               Map sessionMap,
                                               Map applicationMap,
                                               javax.servlet.http.HttpServletRequest request,
                                               javax.servlet.http.HttpServletResponse response,
                                               javax.servlet.ServletContext servletContext)
Merge all application and servlet attributes into a single HashMap to represent the entire Action context.

参数:
requestMap - a Map of all request attributes.
parameterMap - a Map of all request parameters.
sessionMap - a Map of all session attributes.
applicationMap - a Map of all servlet context attributes.
request - the HttpServletRequest object.
response - the HttpServletResponse object.
servletContext - the ServletContextmapping object.
返回:
a HashMap representing the Action context.

prepare

public void prepare(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
Prepare a request, including setting the encoding and locale.

参数:
request - The request
response - The response

wrapRequest

public javax.servlet.http.HttpServletRequest wrapRequest(javax.servlet.http.HttpServletRequest request,
                                                         javax.servlet.ServletContext servletContext)
                                                  throws IOException
Wrap and return the given request or return the original request object.

This method transparently handles multipart data as a wrapped class around the given request. Override this method to handle multipart requests in a special way or to handle other types of requests. Note, MultiPartRequestWrapper is flexible - look first to that object before overriding this method to handle multipart data.

参数:
request - the HttpServletRequest object.
servletContext - Our ServletContext object
返回:
a wrapped request or original request.
抛出:
IOException - on any error.
另请参见:
MultiPartRequestWrapper

cleanUpRequest

public void cleanUpRequest(javax.servlet.http.HttpServletRequest request)
Removes all the files created by MultiPartRequestWrapper.

参数:
request - the HttpServletRequest object.
另请参见:
MultiPartRequestWrapper

sendError

public void sendError(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response,
                      javax.servlet.ServletContext ctx,
                      int code,
                      Exception e)
Send an HTTP error response code.

参数:
request - the HttpServletRequest object.
response - the HttpServletResponse object.
code - the HttpServletResponse error code (see HttpServletResponse for possible error codes).
e - the Exception that is reported.
ctx - the ServletContext object.

cleanUpAfterInit

public void cleanUpAfterInit()
Cleanup any resources used to initialise Dispatcher


getConfigurationManager

public com.opensymphony.xwork2.config.ConfigurationManager getConfigurationManager()
Expose the ConfigurationManager instance.

返回:
The instance

setConfigurationManager

public void setConfigurationManager(com.opensymphony.xwork2.config.ConfigurationManager mgr)
已过时。 should be removed as is used only in tests

Modify the ConfigurationManager instance

参数:
mgr - The configuration manager

getContainer

public com.opensymphony.xwork2.inject.Container getContainer()
Expose the dependency injection container.

返回:
Our dependency injection container