Javatpoint Logo
Javatpoint Logo

Struts 2 prepare interceptor example

The prepare interceptor calls prepre() method on the action if it implements Preparable interface. It calls prepare() method before the execute() method.

To use the prepare interceptor, you need to implement Preparable interface in your action class and override its method prepare.

It is found in the default stack bydefault. So you don't need to specify it explicitely.

Parameters of prepare interceptor

There is only 1 parameter defined for prepare interceptor.

ParameterDescription
alwaysInvokePrepare It is set to true bydefault.

Example of prepare interceptor


Action class

The action class must implement the Preparable interface and override its method prepare().

You can see output on the console, preparation logic is printed before the actual logic.

Output

struts 2 prepare interceptor example output

Now remove the entry of prepare interceptor from the struts.xml file, preparation logic will not be printed.






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