[英]How can I get a value of an action class from another
I have two action classes 我有两个动作课
public class TokenAction extends Action {
private ActionForward getToken(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws IOException {
String token = generateToken();
response.setContentType("text/plain");
response.getWriter().print(token);
return null;
}
and 和
public class ActionTwo extends Action{
private ActionForward doSomething(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) {
token = ???
return actionMapping.findForward("page");
}
}
How can I get in ActionTwo from TokenAction? 如何从TokenAction进入ActionTwo?
Basically, in Java there are multiple ways to pass objects across contexts, the most popular being likely: 基本上,在Java中,有多种方法可以跨上下文传递对象,最流行的可能是:
In your case, since the parameters passed to the methods seem to have a lifetime that encompasses both calls (although it's hard to say without the specifics), you should probably store them in the parameters ( HttpServletResponse
isn't very useful for that purpose, but the ActionMapping
and ActionForm
likely are). 在您的情况下,由于传递给方法的参数似乎有一个包含两个调用的生命周期(尽管很难说没有细节),因此您可能应该将它们存储在参数中( HttpServletResponse
对于此目的不是很有用,但ActionMapping
和ActionForm
可能是)。 If your Action
s are created in the context of some controller, you could use the controller to pass the parameter instead. 如果您的Action
是在某个控制器的上下文中创建的,则可以使用控制器来传递参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.