Struts的Action跳转方式,以及传参方式,chain跳转方式研究

        

ZdcTestChainType跳转到ZdcTestChainTypeDest

有两种方式:redirectAction和chain

redirectAction方式:参数actionName在result 内部

chainAction方式:参数actionName在result 外部

 <!-- <action name="ZdcTestChainType" class="com.how2java.action.ZdcTestChainType">
              <result name="success" type="redirectAction"> 
                  <param name="chainName">woshininnnv</param>
                  <param name="actionName">ZdcTestChainTypeDest</param>
              </result>
          </action> -->
          
          <action name="ZdcTestChainType" class="com.how2java.action.ZdcTestChainType">
              <param name="chainName">woshininnnv</param>
              <result name="success" type="chain">
                  <param name="actionName">ZdcTestChainTypeDest</param>
              </result>
          </action> 
          
          <action name="ZdcTestChainTypeDest" class="com.how2java.action.ZdcTestChainTypeDest">
          </action>

public class ZdcTestChainType  extends ActionSupport{

    public String execute() throws Exception {
        //ActionContext.getContext().put("chainName", "毛线");
        return SUCCESS;
    }
}

public class ZdcTestChainTypeDest  extends ActionSupport{
    private String chainName;
    
    public String getChainName() {
        return chainName;
    }

    public void setChainName(String chainName) {
        this.chainName = chainName;
    }


    public String execute() throws Exception {
        System.out.println(chainName);
        System.out.println(ActionContext.getContext().get("chainName"));
        
        HttpServletResponse response = ServletActionContext.getResponse();
        String str =new String(("<script> alert('"+chainName+"');</script>").getBytes(),"UTF-8");
        PrintWriter out=null;
        try {
            out = response.getWriter();
            out.print(str.toString());
            out.close();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }
}

 

 

注意1,这里的${}不起作用,传递到后台的是字符串:${chainScourceData}

<action name="ZdcTestChainType" class="com.how2java.action.ZdcTestChainType">
              <param name="chainName">${chainScourceData}</param>  <!--${}不起作用 按原字符串传递 -->
              <result name="success" type="chain">
                  <param name="actionName">ZdcTestChainTypeDest</param>
              </result>
</action> 

注意2,网上所说的不指定<param name="chainName">,直接通过get,set传递参数,时需要建立表单的

其中的一个坑坑: https://blog.csdn.net/randomnet/article/details/8656759

在execute方法中修改参数,会被struts偷偷的屏蔽,或者说根本不起作用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值