In this tutorial you will learn about the Struts 2 ActionContext and its application with practical example.
Struts 2 ActionContext
The ActionContext is the context in which an Action is executed. This is a container of objects an action needs for execution like session, parameters, locale, etc.
The value stored in ActionContext are unique per thread so the ActionContext is thread local. ActionContext class is child of an Object class and implements Serializable interface.
public class ActionContext extends Object implements Serializable
By the calling of getContext() method of ActionContext class we can get reference of ActionContext.
Struts 2 ActionContext Methods
There are some useful methods which are listed below
1.Object get(String key): This method is used to returns a value that is stored in current ActionContext using the value’s key.
2.String getName(): This method returns the Name of the current Action and return type will be String.
3.static ActionContext getContext(): This method is used to returns the ActionContext reference.
4.Container setContainer(Container cont): This method is used to sets the container
5.Container getContainer(): This method is used to get the container.
6.void put(String key, Object value): This method is used to stores a value in current ActionContext.
7.void setValueStack(ValueStack stack): This method is used to sets the OGNL value stack.
8.void setSession(Map<String,Object> session): This method is used to sets a map of action session values.
9.void setParameters(HttpParameters params): This method is used to sets the action parameters
10.void setLocale(Locale locale): This method is used to sets the Locale for the current action