java相关:Struts2动态结果集代码示例
发布于 2020-11-30|
复制链接
摘记: 动态结果集可以在action中指定要跳转的页面(${}是OJNL表达式,不是EL表达式)struts.xml:
```xhtml
..
动态结果集可以在action中指定要跳转的页面(${}是OJNL表达式,不是EL表达式)struts.xml:
```xhtml
${r}
```
ResultAction.java:
```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;
}
}
```
前台链接:
```xhtml
/r/result_mul?type=1" rel="external nofollow" >动态结果集1
/r/result_mul?type=2" rel="external nofollow" >动态结果集2
/r/result_mul?type=3" rel="external nofollow" >动态结果集3
```