日期:2014-05-17 浏览次数:20894 次
public class UserConverter3 extends StrutsTypeConverter {
@Override
public Object convertFromString(Map context, String[] values, Class toClass) {
List<User> users = new ArrayList<User>();
for(String value:values){
System.out.println("b");
StringTokenizer st = new StringTokenizer(value,";");
User user = new User();
user.setUsername(st.nextToken());
user.setPassword(st.nextToken());
users.add(user);
}
System.out.println("a");
return users;
}
@Override
public String convertToString(Map context, Object o) {
// TODO Auto-generated method stub
return null;
}
}
public class UserAction2 extends ActionSupport {
private List<User> user;
public List<User> getUser() {
return user;
}
public void setUsers(List<User> user) {
this.user = user;
}
@Override
public String execute() throws Exception {
for(User u:user){
System.out.println(u.getUsername());
System.out.println(u.getPassword());
}
return SUCCESS;
}
}
user=convert.UserConverter3
<action name = "UserAction2" class = "struts2.UserAction2">
<result name="success">/output.jsp</result>
</action>
<form action = "UserAction2.action">
userinfo1:<input type = "text" name = "user"/>
userinfo1:<input type = "text" name = "user"/>
userinfo1:<input type = "text" name = "user"/>
userinfo1:<input type = "text" name = "user"/>
<input type = "submit" value = "提交">
</form>