Struts 2ダイナミック結果セットコード例


動的結果セットは、actionでジャンプするページ($)を指定できます。OJNL式です。EL式ではありません。
struts.xml:

<package name="resultTypes" namespace="/r" extends="struts-default"> 
<action name="result_mul" class="cn.edu.hpu.action.ResultAction"> 
<!--                              --> 
  <result>${r}</result> 
</action> 
</package> 
Resoult Action.java:

package cn.edu.hpu.action;  
import com.opensymphony.xwork2.ActionSupport; 
public class ResultAction extends ActionSupport {  
  private int type;    
  private String r="/Hello.jsp";    
  public int getType() { 
    return type; 
  }   
  public void setType(int type) { 
    this.type = type; 
  }   
  public String getR() { 
    return r; 
  } 
  public void setR(String r) { 
    this.r = r; 
  } 
  public String execute() throws Exception { 
    //  r          ,         ${r} 
    //      
    if(type==1) r="/User_Add_success.jsp"; 
    else if(type==2) r="/User_Add_error.jsp"; 
    return SUCCESS; 
  } 
} 
フロントリンク:

<a href="<%=basePath %>/r/result_mul?type=1" rel="external nofollow" >     1</a> 
<a href="<%=basePath %>/r/result_mul?type=2" rel="external nofollow" >     2</a> 
<a href="<%=basePath %>/r/result_mul?type=3" rel="external nofollow" >     3</a> 
締め括りをつける
以上が、Struts 2ダイナミック結果セットコード例のすべての内容です。Struts 2の勉強に役立ちます。興味のある方はこの駅の関連記事を参照してください。Strutsとservletが共存できない問題解決方法 、 Struts 2アップロードファイルのサイズ制限方法の解析を修正します。 、 struts 2開発プロセスと詳細配置などです。問題があったらいつでもメッセージを残してください。