一.說明
舉個例子,如果要根據請求參數的不同來訪問不同的頁面怎麼來做呢,可以用動態結果集來做,參數不同,到action中做對比,不同的參數指定不同的url字符串,然後在struts.xml中的result中利用${}取出url,具體看下面。
二. 栗子
1.先看實現效果:
點擊之後也可以成功跳轉
2. index文件
3. struts.xml
4. Action類
package com.bjsxt.struts2.user.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private int type;
private String r;
public String getR() {
return r;
}
public void setR(String r) {
this.r = r;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public String execute() throws Exception {
if(type == 1) r="/user_success.jsp";
else if (type == 2) r="/user_error.jsp";
return "success";
}
}
我們接收到了參數,然後在execute中進行比對,然後給action'類中的成員變量r賦值url,然後struts在result中yong${}取出來三.說明
這個東西在實際開發中並不常用。