发的说法是阿斯蒂芬安抚
package com.bdyc.action;import java.net.URLEncoder;import java.util.ArrayList;import java.util.Date;import java.util.List;import com.bdyc.model.User;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport{ private User user; private String username; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } /** * 查询所有用户信息 * @return */ public String list(){ ListuserList= new ArrayList (); for (int i = 0; i < 10; i++) { String[] favs = {"1","2"}; User user = new User(i+1, "测试用户"+i, "123123", 1, new Date(), 2000.0f+i, favs); userList.add(user); } //将用户集合传递给list.jsp页面显示 ActionContext.getContext().put("userList",userList); return "listUI"; } /** * 注册方法 * @return */ public String reg(){ //接受页面参数,类型转换 System.out.println(user); try { username = URLEncoder.encode(user.getUsername()); } catch (Exception e) { e.printStackTrace(); } //调用业务逻辑 System.out.println("注册成功"); //负责页面跳转 return "regSuccess"; }}
1 package com.bdyc.action; 2 3 import java.net.URLEncoder; 4 import java.util.ArrayList; 5 import java.util.Date; 6 import java.util.List; 7 8 import com.bdyc.model.User; 9 import com.opensymphony.xwork2.ActionContext;10 import com.opensymphony.xwork2.ActionSupport;11 12 public class UserAction extends ActionSupport{13 private User user;14 private String username;15 16 public String getUsername() {17 return username;18 }19 public void setUsername(String username) {20 this.username = username;21 }22 public User getUser() {23 return user;24 }25 public void setUser(User user) {26 this.user = user;27 }28 29 /**30 * 查询所有用户信息31 * @return32 */33 public String list(){34 ListuserList= new ArrayList ();35 for (int i = 0; i < 10; i++) {36 String[] favs = {"1","2"};37 User user = new User(i+1, "测试用户"+i, "123123", 1, new Date(), 2000.0f+i, favs);38 userList.add(user);39 }40 //将用户集合传递给list.jsp页面显示41 ActionContext.getContext().put("userList",userList);42 return "listUI";43 }44 45 /**46 * 注册方法47 * @return48 */49 public String reg(){50 //接受页面参数,类型转换51 System.out.println(user);52 try {53 username = URLEncoder.encode(user.getUsername());54 } catch (Exception e) {55 e.printStackTrace();56 }57 //调用业务逻辑58 System.out.println("注册成功");59 60 //负责页面跳转61 return "regSuccess";62 }63 }