[转帖] Struts2和JSP之间,List对象的传递_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2708 | 回复: 0   主题: [转帖] Struts2和JSP之间,List对象的传递        下一篇 
    本主题由 koei 于 2014-5-2 16:25:27 移动
522080330
注册用户
等级:少校
经验:1478
发帖:79
精华:20
注册:2013-1-18
状态:离线
发送短消息息给522080330 加好友    发送短消息息给522080330 发消息
发表于: IP:您无权察看 2013-1-23 16:06:42 | [全部帖] [楼主帖] 楼主

1. 需要传递的POJO对象.

北京联动北方科技有限公司

/**
* @author cheney
*
* @date Jan 7, 2013
*/
public class User {
      private String id;
      private String name;
      private String password;
      /**
      * @return the id
      */
      public String getId() {
            return id;
      }
      /**
      * @param id
      * the id to set
      */
      public void setId(String id) {
            this.id = id;
      }
      /**
      * @return the name
      */
      public String getName() {
            return name;
      }
      /**
      * @param name
      * the name to set
      */
      public void setName(String name) {
            this.name = name;
      }
      /**
      * @return the password
      */
      public String getPassword() {
            return password;
      }
      /**
      * @param password
      * the password to set
      */
      public void setPassword(String password) {
            this.password = password;
      }
}


北京联动北方科技有限公司

2. Action中的初始化和对jsp页面提交对象的接受

北京联动北方科技有限公司

import java.util.LinkedList;
import java.util.List;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.conversion.annotations.ConversionRule;
import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
import com.tydic.base.BaseAction;
/**
* @author cheney
*
* @date Aug 15, 2012
*/
public class UserAction extends BaseAction {
      private List<User> mapList;
      /**
      *
      */
      private static final long serialVersionUID = 3551905855359325103L;
@Action(value = /service/flowcard/user/init, results = { @Result(name = SUCCESS, location = /jsp/flowcard/u_index.jsp) })
      public String init() throws Exception {
            System.out.println(init.................);
            mapList = new LinkedList<User>();
            User user1 = new User();
            user1.setId(1);
            user1.setName(chen);
            user1.setPassword(aa);
            User user2 = new User();
            user2.setId(2);
            user2.setName(fa);
            user2.setPassword(11);
            User user3 = new User();
            user3.setId(3);
            user3.setName(gaaa);
            user3.setPassword(222);
            User user4 = new User();
            user4.setId(4);
            user4.setName(mms);
            user4.setPassword(w2w);
            mapList.add(user1);
            mapList.add(user2);
            mapList.add(user3);
            mapList.add(user4);
            return SUCCESS;
      }
@Action(value = /service/flowcard/user/register, results = { @Result(name = SUCCESS, location = /jsp/flowcard/u_succ.jsp) })
      public String register() throws Exception {
            System.out.println(register.................);
            // System.out.println(mapList.size());
            for (int i = 0; i < mapList.size(); i++) {
                  System.out.println(mapList.get(i).getId());
                  System.out.println(mapList.get(i).getName());
                  System.out.println(mapList.get(i).getPassword());
                  System.out.println(=============================);
            }
            return SUCCESS;
      }
      /**
      * @return the mapList
      */
      public List<User> getMapList() {
            return mapList;
      }
      /**
      * @param mapList
      * the mapList to set
      */
      @TypeConversion(rule = ConversionRule.COLLECTION, converter = com.tydic.flowcard.action.User)
      public void setMapList(List<User> mapList) {
            this.mapList = mapList;
      }
}


北京联动北方科技有限公司

3. JSP页面的封装

?
<body>
<div align=center>
<form id=formId action=/service/flowcard/user/register.action method=post>
<c:forEach var=ml items={mapList} varStatus=status>
<input type=hidden value={ml.id} name=mapList[{status.index}].id />
<input type=hidden value={ml.name} name=mapList[{status.index}].name />
<input type=hidden value={ml.password} name=mapList[{status.index}].password />
</c:forEach>
<input type=submit value=SUBMIT />
</form>
</div>
</body>


该贴由koei转至本版2014-5-2 16:25:27



赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论