您现在的位置: 365建站网 > 365学习 > struts2 select标签 action传递list集合到jsp,jsp提交到action

struts2 select标签 action传递list集合到jsp,jsp提交到action

文章来源:365jz.com     点击数:9217    更新时间:2009-09-16 11:48   参与评论

思路: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;
 }
 
}

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛


发表评论 (9217人查看-4条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码: 点击我更换图片
最新评论
------分隔线----------------------------