• <i id='k9DTm'><tr id='k9DTm'><dt id='k9DTm'><q id='k9DTm'><span id='k9DTm'><b id='k9DTm'><form id='k9DTm'><ins id='k9DTm'></ins><ul id='k9DTm'></ul><sub id='k9DTm'></sub></form><legend id='k9DTm'></legend><bdo id='k9DTm'><pre id='k9DTm'><center id='k9DTm'></center></pre></bdo></b><th id='k9DTm'></th></span></q></dt></tr></i><div id='k9DTm'><tfoot id='k9DTm'></tfoot><dl id='k9DTm'><fieldset id='k9DTm'></fieldset></dl></div>
  • <legend id='k9DTm'><style id='k9DTm'><dir id='k9DTm'><q id='k9DTm'></q></dir></style></legend>
      <bdo id='k9DTm'></bdo><ul id='k9DTm'></ul>

      <small id='k9DTm'></small><noframes id='k9DTm'>

    1. <tfoot id='k9DTm'></tfoot>

        如何将 Action 类变量值传递给 Struts 2 中的另一个 Action 类

        时间:2023-09-24

              <small id='5qmEr'></small><noframes id='5qmEr'>

              <tfoot id='5qmEr'></tfoot>
                <tbody id='5qmEr'></tbody>

              • <bdo id='5qmEr'></bdo><ul id='5qmEr'></ul>

                <legend id='5qmEr'><style id='5qmEr'><dir id='5qmEr'><q id='5qmEr'></q></dir></style></legend>
                • <i id='5qmEr'><tr id='5qmEr'><dt id='5qmEr'><q id='5qmEr'><span id='5qmEr'><b id='5qmEr'><form id='5qmEr'><ins id='5qmEr'></ins><ul id='5qmEr'></ul><sub id='5qmEr'></sub></form><legend id='5qmEr'></legend><bdo id='5qmEr'><pre id='5qmEr'><center id='5qmEr'></center></pre></bdo></b><th id='5qmEr'></th></span></q></dt></tr></i><div id='5qmEr'><tfoot id='5qmEr'></tfoot><dl id='5qmEr'><fieldset id='5qmEr'></fieldset></dl></div>
                  本文介绍了如何将 Action 类变量值传递给 Struts 2 中的另一个 Action 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何将 Action 类变量值传递给 Struts 2 中的另一个 Action 类?

                  How to pass Action class variable value into another Action class in Struts 2?

                  我想在另一个动作类中使用在查询变量中检索到的那个.

                  I wanted to use that retrieved in the query variable in another action class.

                  推荐答案

                  动作可以通过不同的方式相互通信,以及它们在不同的线程中运行并且不共享动作上下文.最流行的方法是通过请求或在 URL 中传递参数,XWork 转换器将在 OGNL 的帮助下将它们转换为动作属性.

                  There are different ways the actions could communicate with each other as well as they running in different threads and don't share the action context. The most popular way is to pass parameters with the request or in the URL and XWork converter will convert them to the action properties with the help of OGNL.

                  但我认为 LoginAction 的目的是通过用户的凭据 (电子邮件、用户名、密码) 对用户进行身份验证,并将此信息保存在会话映射中.它是可以在动作之间共享的公共资源.要获得可用于操作和其他操作的会话映射,他们应该实现 SessionAware.它将帮助 Struts 将会话映射注入到 action 属性中.如果您想在应用程序的许多操作中使用会话,那么不要在每个操作中实现此接口,您可以创建一个基本操作.

                  But I think the purpose of the LoginAction is to authenticate the user by their credentials (email, username, password) and save this information in the session map. It is a common resource that could be shared between actions. To get the session map available to the action and other actions they should implement the SessionAware. It will help the Struts to inject the session map to the action property. If you want to use the session in many actions over the application then to not implement this interface in every action you could create a base action.

                  public class BaseAction extends ActionSupport implements SessionAware {
                  
                    private Map<String, Object> session;
                  
                    public setSession(Map<String, Object> session){
                      this.session = session;
                    }
                  
                    public Map<String, Object> getSession(){
                      return session;
                    }
                  }
                  

                  然后操作将扩展基本操作以获得会话兼容性.

                  then actions will extend the base action to get the session compability.

                  public class LoginAction extends BaseAction {
                  
                    @Override
                    public String execute() throws Exception {
                      User user = getUserService().findBy(username, email, password);
                      getSession().put("user", user);
                  
                      return SUCCESS;
                    }
                  
                  }
                  

                  现在用户在会话中,您可以从其他操作或 JSP 中获取会话,并从 session 映射中获取 user 对象.

                  Now the user in the session and you could get the session from other action or JSP and user object from the session map.

                  public class InboxAction extends BaseAction {
                  
                    @Override
                    public String execute() throws Exception {
                      User user = (User) getSession().get("user");
                  
                      return SUCCESS;
                    }
                  
                  } 
                  

                  这篇关于如何将 Action 类变量值传递给 Struts 2 中的另一个 Action 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Struts 2 - 拦截器重置响应 JSON 对象 下一篇:如何在 Struts 2 中捕获默认拦截器堆栈抛出的异常?

                  相关文章

                • <small id='ORtCd'></small><noframes id='ORtCd'>

                  • <bdo id='ORtCd'></bdo><ul id='ORtCd'></ul>
                • <i id='ORtCd'><tr id='ORtCd'><dt id='ORtCd'><q id='ORtCd'><span id='ORtCd'><b id='ORtCd'><form id='ORtCd'><ins id='ORtCd'></ins><ul id='ORtCd'></ul><sub id='ORtCd'></sub></form><legend id='ORtCd'></legend><bdo id='ORtCd'><pre id='ORtCd'><center id='ORtCd'></center></pre></bdo></b><th id='ORtCd'></th></span></q></dt></tr></i><div id='ORtCd'><tfoot id='ORtCd'></tfoot><dl id='ORtCd'><fieldset id='ORtCd'></fieldset></dl></div>
                      <legend id='ORtCd'><style id='ORtCd'><dir id='ORtCd'><q id='ORtCd'></q></dir></style></legend>

                    1. <tfoot id='ORtCd'></tfoot>