Package org.apache.struts2
Class ActionContext
java.lang.Object
org.apache.struts2.ActionContext
- All Implemented Interfaces:
- Serializable
 The ActionContext is the context in which an Action is executed. Each context is basically a
 container of objects an action needs for execution like the session, parameters, locale, etc.
 
 The ActionContext is thread local which means that values stored in the ActionContext are
 unique per thread. See the ThreadLocal class for more information. The benefit of
 this is you don't need to worry about a user specific action context, you just get it:
 
ActionContext context = ActionContext.getContext();
 Finally, because of the thread local usage you don't need to worry about making your actions thread safe.
- Author:
- Patrick Lightbody, Bill Lynch (docs)
- See Also:
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedActionContext(Map<String, Object> context) Creates a new ActionContext initialized with another context.
- 
Method SummaryModifier and TypeMethodDescriptionbind()Binds this context with the current threadstatic ActionContextbind(ActionContext actionContext) Binds the provided context with the current threadstatic voidclear()Wipes out current ActionContext, use wisely!static booleancontainsValueStack(Map<String, Object> context) final booleanReturns a value that is stored in the current ActionContext by doing a lookup using the value's key.Gets the action invocation (the execution state).Gets ActionMapping associated with current actionGets the name of the current Action.Returns a Map of the ServletContext when in a servlet environment or a generic application level Map otherwise.Sets the container for this requeststatic ActionContextReturns the ActionContext specific to the current thread.Gets the context map.Gets the map of conversion errors which occurred when executing the action.<T> TgetInstance(Class<T> type) Gets the Locale of the current action.jakarta.servlet.jsp.PageContextGets PageContext associated with current actionReturns a Map of the HttpServletRequest parameters when in a servlet environment or a generic Map of parameters otherwise.jakarta.servlet.ServletContextGets ServletContext associated with current actionjakarta.servlet.http.HttpServletRequestGets ServletRequest associated with current actionjakarta.servlet.http.HttpServletResponseGets ServletResponse associated with current actionGets the Map of HttpSession values when in a servlet environment or a generic session map otherwise.Gets the OGNL value stack.final inthashCode()static ActionContextof()Creates a new ActionContext based on empty Mapstatic ActionContextCreates a new ActionContext based on passed in MapvoidStores a value in the current ActionContext.Adds arbitrary key to action contextwithActionInvocation(ActionInvocation actionInvocation) Sets the action invocation (the execution state).withActionMapping(ActionMapping actionMapping) Assigns ActionMapping to action contextwithActionName(String actionName) Sets the name of the current Action in the ActionContext.withApplication(Map<String, Object> application) Sets the action's application context.withContainer(Container container) Gets the container for this requestwithConversionErrors(Map<String, ConversionData> conversionErrors) Sets conversion errors which occurred when executing the action.withExtraContext(Map<String, Object> extraContext) Assigns an extra context map to action contextwithLocale(Locale locale) Sets the Locale for the current action.withPageContext(jakarta.servlet.jsp.PageContext pageContext) Assigns PageContext to action contextwithParameters(HttpParameters parameters) Sets the action parameters.withServletContext(jakarta.servlet.ServletContext servletContext) Assigns ServletContext to action contextwithServletRequest(jakarta.servlet.http.HttpServletRequest request) Assigns ServletRequest to action contextwithServletResponse(jakarta.servlet.http.HttpServletResponse response) Assigns ServletResponse to action contextwithSession(Map<String, Object> session) Sets a map of action session values.withValueStack(ValueStack valueStack) Sets the OGNL value stack.
- 
Constructor Details- 
ActionContextCreates a new ActionContext initialized with another context.- Parameters:
- context- a context map.
 
 
- 
- 
Method Details- 
ofCreates a new ActionContext based on passed in Map- Parameters:
- context- a map with context values
- Returns:
- new ActionContext
 
- 
ofCreates a new ActionContext based on empty Map- Returns:
- new ActionContext
 
- 
bindBinds the provided context with the current thread- Parameters:
- actionContext- context to bind to the thread
- Returns:
- context which was bound to the thread
 
- 
containsValueStack
- 
bindBinds this context with the current thread- Returns:
- this context which was bound to the thread
 
- 
clearpublic static void clear()Wipes out current ActionContext, use wisely!
- 
getContextReturns the ActionContext specific to the current thread.- Returns:
- the ActionContext for the current thread, is never null.
 
- 
withActionInvocationSets the action invocation (the execution state).- Parameters:
- actionInvocation- the action execution state.
 
- 
getActionInvocationGets the action invocation (the execution state).- Returns:
- the action invocation (the execution state).
 
- 
withApplicationSets the action's application context.- Parameters:
- application- the action's application context.
 
- 
getApplicationReturns a Map of the ServletContext when in a servlet environment or a generic application level Map otherwise.- Returns:
- a Map of ServletContext or generic application level Map
 
- 
getContextMapGets the context map.- Returns:
- the context map.
 
- 
withConversionErrorsSets conversion errors which occurred when executing the action.- Parameters:
- conversionErrors- a Map of errors which occurred when executing the action.
 
- 
getConversionErrorsGets the map of conversion errors which occurred when executing the action.- Returns:
- the map of conversion errors which occurred when executing the action or an empty map if there were no errors.
 
- 
withLocaleSets the Locale for the current action.- Parameters:
- locale- the Locale for the current action.
 
- 
getLocaleGets the Locale of the current action. If no locale was ever specified the platform'sdefault localeis used.- Returns:
- the Locale of the current action.
 
- 
withActionNameSets the name of the current Action in the ActionContext.- Parameters:
- actionName- the name of the current action.
 
- 
getActionNameGets the name of the current Action.- Returns:
- the name of the current action.
 
- 
withParametersSets the action parameters.- Parameters:
- parameters- the parameters for the current action.
 
- 
getParametersReturns a Map of the HttpServletRequest parameters when in a servlet environment or a generic Map of parameters otherwise.- Returns:
- a Map of HttpServletRequest parameters or a multipart map when in a servlet environment, or a generic Map of parameters otherwise.
 
- 
withSessionSets a map of action session values.- Parameters:
- session- the session values.
 
- 
getSessionGets the Map of HttpSession values when in a servlet environment or a generic session map otherwise.- Returns:
- the Map of HttpSession values when in a servlet environment or a generic session map otherwise.
 
- 
withValueStackSets the OGNL value stack.- Parameters:
- valueStack- the OGNL value stack.
 
- 
getValueStackGets the OGNL value stack.- Returns:
- the OGNL value stack.
 
- 
withContainerGets the container for this request- Parameters:
- container- The container
 
- 
getContainerSets the container for this request- Returns:
- The container
 
- 
getInstance
- 
getReturns a value that is stored in the current ActionContext by doing a lookup using the value's key.- Parameters:
- key- the key used to find the value.
- Returns:
- the value that was found using the key or null if the key was not found.
 
- 
putStores a value in the current ActionContext. The value can be looked up using the key.- Parameters:
- key- the key of the value.
- value- the value to be stored.
 
- 
getServletContextpublic jakarta.servlet.ServletContext getServletContext()Gets ServletContext associated with current action- Returns:
- current ServletContext
 
- 
withServletContextAssigns ServletContext to action context- Parameters:
- servletContext- associated with current request
- Returns:
- ActionContext
 
- 
getServletRequestpublic jakarta.servlet.http.HttpServletRequest getServletRequest()Gets ServletRequest associated with current action- Returns:
- current ServletRequest
 
- 
withServletRequestAssigns ServletRequest to action context- Parameters:
- request- associated with current request
- Returns:
- ActionContext
 
- 
getServletResponsepublic jakarta.servlet.http.HttpServletResponse getServletResponse()Gets ServletResponse associated with current action- Returns:
- current ServletResponse
 
- 
withServletResponseAssigns ServletResponse to action context- Parameters:
- response- associated with current request
- Returns:
- ActionContext
 
- 
getPageContextpublic jakarta.servlet.jsp.PageContext getPageContext()Gets PageContext associated with current action- Returns:
- current PageContext
 
- 
withPageContextAssigns PageContext to action context- Parameters:
- pageContext- associated with current request
- Returns:
- ActionContext
 
- 
getActionMappingGets ActionMapping associated with current action- Returns:
- current ActionMapping
 
- 
withActionMappingAssigns ActionMapping to action context- Parameters:
- actionMapping- associated with current request
- Returns:
- ActionContext
 
- 
withExtraContextAssigns an extra context map to action context- Parameters:
- extraContext- to add to the current action context
- Returns:
- ActionContext
 
- 
withAdds arbitrary key to action context- Parameters:
- key- a string
- value- an object
- Returns:
- ActionContext
 
- 
equals
- 
hashCodepublic final int hashCode()
 
-