配置文件

 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 }
posted on 2012-10-17 21:41  elleniou  阅读(1913)  评论(0编辑  收藏  举报