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.youkuaiyun.com/randomnet/article/details/8656759
在execute方法中修改参数,会被struts偷偷的屏蔽,或者说根本不起作用