struts2 result随笔


    一、result:chain(从一个Action转发到另一个Action)

    chain结果类型有4个属性,分别是:

    actionName (default) - the name of the action that will be chained to

    namespace - used to determine which namespace the Action is in that we're chaining. If namespace is null, this defaults to the current namespace

    method - used to specify another method on target action to be invoked. If null, this defaults to execute method

    skipActions - (optional) the list of comma separated action names for the actions that could be chained to

   eg:

         public String hotGoods() {

      try {
        QueryRule queryRule=QueryRule.getInstance();
        queryRule.addEqual("isNew", "0");
        List<ProductInfo> productInfoList = geProductInfoService.queryGeProductInfoByQueryRule(queryRule);                                               
        super.getRequest().setAttribute("productInfoList ", productInfoList );
        }catch (Exception e) {

                       e.printStackTrace();

         }
        return SUCCESS;

        }

      <action name="hotGoods" class="listAction" method="hotGoods">
        <result name="success" type="chain">hotGoods1</result>
      </action    

               

      public String hotGoods1() {
        try {
          List<ProductInfo> productInfoList = (List<ProductInfo>)super.getRequest().getAttribute("productInfoList ");
          super.getRequest().setAttribute("productInfoList ", productInfoList );
          } catch (Exception e) {
              e.printStackTrace();
          }
            return SUCCESS;

          }

      <action name="hotGoods1" class="listAction" method="hotGoods1">
        <result name="success">index.jsp</result>
      </action>

       index.jsp可以得到productInfoList 的值

 二、result:redirect(从一个Action转发到另一个Action)

    public String getFamilyCardUrl() {
      try {
      familyCardWeixinURL = “*****”;

      //familyCardWeixinURL内容为*****.getFamilyCardOpenId.do?code=code&****
      return "familyCardWeixinURL";
      } catch (Exception e) {
      e.printStackTrace();
      }
      return "fail";
      }

      <action name="getFamilyCardOpenId" class="**Action" method="getFamilyCardOpenId">
        <result name="familyCardWeixinURL" type="redirect">${familyCardWeixinURL}</result>
        <result name="fail" type="redirect">/common/500Phone.jsp</result>
      </action>

      getFamilyCardOpenId所在action中需要有全局变量familyCardWeixinURL及其get,set方法

  //未完成

关注公众号:CS尼克。我们一起学习计算机相关知识

原文地址:https://www.cnblogs.com/shueixue/p/5709954.html