Reputation:
I am directly forwarded to a method within my action class (by struts.xml) but I do not actually create a new instance of my Action Class. I ask because I have some variables to set before anything can be done with the ActionClass, and I thought constructors might help me do just that.
Upvotes: 2
Views: 2899
Reputation: 23587
Struts 2 provides a Prepare Interceptor to prepare your data before the actual execute method runs.This interceptor calls prepare() on actions which implement Preparable. Some of the use cases for using the prepare method in your action class are
In short this interceptor is like an init/constructor for the Action class and you have all control to initialize any required parameters or do any initial lookup.
For details refer to the interceptor page prepare-interceptor
Upvotes: 4