首页 > 编程 > Java > 正文

Struts2动态结果集代码示例

2019-11-26 11:17:03
字体:
来源:转载
供稿:网友

动态结果集可以在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> 

ResultAction.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> 

总结

以上就是本文关于Struts2动态结果集代码示例的全部内容,希望对大家学习Struts2有所帮助。感兴趣的朋友可以参阅本站更多相关文章:Struts和servlet不能共存问题解决方法 、 Struts2修改上传文件大小限制方法解析 、 struts2开发流程及详细配置等。有问题的话可以随时留言,小编会及时回复大家的。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表