Struts2-动态结果集

配置文件

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 4     "http://struts.apache.org/dtds/struts-2.0.dtd">
 5 
 6 <struts>
 7     <constant name="struts.devMode" value="true" />
 8     <package name="user" namespace="/user" extends="struts-default">
 9         
10         <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
11         <!-- 表示往值栈里面取值 在该类中r是action的属性 而r是传入的数值所以是动态结果集 -->
12             <result>${r}</result>
13         </action>        
14     </package>
15         
16 </struts>

UserAction详情

 1 package com.bjsxt.struts2.user.action;
 2 
 3 import com.opensymphony.xwork2.ActionSupport;
 4 
 5 public class UserAction extends ActionSupport {
 6     private int type;
 7     
 8     private String r;
 9 
10     public String getR() {
11         return r;
12     }
13 
14     public void setR(String r) {
15         this.r = r;
16     }
17 
18     public int getType() {
19         return type;
20     }
21 
22     public void setType(int type) {
23         this.type = type;
24     }
25 
26     @Override
27     public String execute() throws Exception {
28         //根据传入数据动态决定跳转的jsp
29         if(type == 1) r="/user_success.jsp";
30         else if (type == 2) r="/user_error.jsp";
31         return "success";
32     }
33 
34 }

转载于:https://www.cnblogs.com/elleniou/archive/2012/10/17/2728566.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值