Struts 2 Components, a request is forwarded to an action class from the browser and returns the result in a browser in between container. Struts framework will contain components where each component can be treated as a core component of the struts framework, these components are utilized to develop web applications but having knowledge of these components is mandatory to learn Struts framework. Following are the Struts 2 Components and their overview.
Interceptors
ValueStack
ActionInnvocation
OGNL
Interceptors
Description
Interceptor is an object, that is invoked (executed) the pre-processing request and post-processing request. Interceptors are used to perform the validations, exceptions handling and display the result in between the execute() method. In struts 2, Interceptors execution is same as the servlet filter execution type. Using Interceptors, One can run the application using validations, and can remove the validations on that application and one cannot deploy the application in the server. If it directly run on the server.
ValueStack
Description
ValueStack is a type of stack, it contains some objects or requests. ValueStack is used for hiding some data internally and execute in execute() method.
ActionInvocation
Description
The ActionInvocation represents the execution state of an action. It holds the action and interceptor objects. ActionInvocation is an interface, it provides some methods by calling the ValueStack, ActionProxy, ActionContext.
Methods
Methods of ActionInvocation Interface.
public ActionContext getInvocationContext() returns the ActionContext object associated with the AcctionInvocation.
public ValueStack getStack() returns the instance of ValueStack object.
public Action getAction() returns the instance of Action associated with this ActionInvocation.
public void invoke() invokes the next class in processing this ActionInvocation.
public ActionProxy getProxy() returns the ActionProxy instance holding this ActionInvocation.
public Result getResult() returns the instance of result.
OGNL
Description
OGNL (Object Graph Navigation Language) is one type of Expression Language. OGNL is used to simplify the ActionContext contains data. These OGNL expressions are used to display the ValueStack object values in browser. Push the values in ValueStack object, then the values is mapped to JSP pages through property tag.
[java]<s:property value="username"/> [/java]
Here, s indicates prefix and name indicate the ValueStack object property key.The struts framework places other objects in ActionContext. The ActionContext map represent the request, session, application scopes.To get the values in scope, the action property is not directly used. So, one need to use # notation.
Summary
Key Points
Struts 2 Components - The components are the core of Struts 2.