思路:SetUserAction.java 传递userlist集合到select.jsp页面,jsp页面传递用户的选择到SelectUserAction.java
User.java
package com.select.bean;
public class User {
private String userno;
private String username;
public User(){
}
public User(String userno,String username){
this.userno = userno;
this.username = username;
}
public String getUserno() {
return userno;
}
public void setUserno(String userno) {
this.userno = userno;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
SetUserAction.java
package com.select.action;
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.select.bean.User;
public class SetUserAction extends ActionSupport {
private List<User> userlist;
public List<User> getUserlist() {
return userlist;
}
public void setUserlist(List<User> userlist) {
this.userlist = userlist;
}
@Override
public String execute() throws Exception {
List<User> userlist = new ArrayList<User>();
User u1 = new User("1000","王雪");
User u2 = new User("1001","刘伟");
User u3 = new User("1002","王金红");
userlist.add(u1);
userlist.add(u2);
userlist.add(u3);
setUserlist(userlist);
return SUCCESS;
}
}
select.jsp
<s:form action="selectuser.action">
<s:select name="user.userno" list="userlist" listKey="userno"
listValue="username" />
<s:submit></s:submit>
</s:form>
SelectUserAction.java
package com.select.action;
import com.opensymphony.xwork2.ActionSupport;
import com.select.bean.User;
public class SelectUserAction extends ActionSupport {
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public String execute() throws Exception {
System.out.print(user.getUserno());
return SUCCESS;
}
}
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛