Chandrasekhar
Chandrasekhar

Reputation: 1215

variable passing in struts action class

we are developing the web application we have different methods in struts2 action class. We are instantiate the one variable and assign some value. We want to use that variable value in another method.

I think this is possible in 2 ways. 1.Using the static variable.But when we are using the static global variable another user is also accessing the same variable value at the same time or override the value with new user. 2. Using the HTTPsession.

Is there any other way to get the assigned value from one method to the another method in action class

Please suggest.

Upvotes: 0

Views: 1880

Answers (2)

Anthony Grist
Anthony Grist

Reputation: 38345

Depending on the control flow of your class, there are two other options:

If the second method is called by the first, simply pass it as a parameter.

Use an instance (rather than static) variable, which will be specific to each instance of your action class. You set the value in the first method, then read it in the other method.

Upvotes: 0

Sathwick
Sathwick

Reputation: 1331

Check with Scope interceptors. This will store the value of the variable in the scope (may be session) once the execution of one method is completed and will retrieve the value just before calling another method.

Upvotes: 1

Related Questions