简体   繁体   English

在struts动作类中传递变量

[英]variable passing in struts action class

we are developing the web application we have different methods in struts2 action class. 我们正在开发Web应用程序,我们在struts2动作类中有不同的方法。 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. 1,使用静态变量但是当我们使用静态全局变量时,另一个用户也同时访问相同的变量值或使用新用户覆盖该值。 2. Using the HTTPsession. 2.使用HTTP会话。

Is there any other way to get the assigned value from one method to the another method in action class 还有其他方法可以将操作类中的一个方法中的赋值分配给另一个方法

Please suggest. 请提出建议。

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. 一旦一个方法的执行完成,它将在范围(可能是会话)中存储变量的值,并在调用另一方法之前检索该值。

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. 您在第一种方法中设置该值,然后在另一种方法中读取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM