Struts 2 Components

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

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

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

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 of ActionInvocation Interface.

OGNL

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.

<s:property value="username"/>

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

• Struts 2 Components – The components are the core of Struts 2.
• Struts 2 Components – OGNL stands for Object Graph Navigation Language.
• Value Stack is the root instance of OGNL.