Javatpoint Logo
Javatpoint Logo

Struts 2 Action

In struts 2, action class is POJO (Plain Old Java Object).

POJO means you are not forced to implement any interface or extend any class.

Generally, execute method should be specified that represents the business logic. The simple action class may look like:

Welcome.java

Action Interface

A convenient approach is to implement the com.opensymphony.xwork2.Action interface that defines 5 constants and one execute method.

5 Constants of Action Interface

Action interface provides 5 constants that can be returned form the action class. They are:

  1. SUCCESS indicates that action execution is successful and a success result should be shown to the user.
  2. ERROR indicates that action execution is failed and a error result should be shown to the user.
  3. LOGIN indicates that user is not logged-in and a login result should be shown to the user.
  4. INPUT indicates that validation is failed and a input result should be shown to the user again.
  5. NONE indicates that action execution is successful but no result should be shown to the user.

Let's see what values are assigned to these constants:

Method of Action Interface

Action interface contains only one method execute that should be implemented overridden by the action class even if you are not forced.

Example of Struts Action that implements Action interface

If we implement the Action interface, we can directly use the constants instead of values.

Welcome.java

ActionSupport class

It is a convenient class that implements many interfaces such as Action, Validateable, ValidationAware, TextProvider, LocaleProvider and Serializable . So it is mostly used instead of Action.

Example of Struts Action that extends ActionSupport class

Let's see the example of Action class that extends the ActionSupport class.

Welcome.java





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA