动态结果集可以在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修改上传文件大小限制方法解析 、 等。有问题的话可以随时留言,小编会及时回复大家的。
如对本文有疑问, 点击进行留言回复!!
Algebra:Chapter 0 - 预备知识: 集合论和categories
springboot + vue上传图片在服务器并实现在线预览
请谨慎使用增强for循环,刚接触Java值得一看(手动狗头)
【Nginx】还不会使用Nginx解决跨域问题?肝这一篇就够了!!
网友评论