看看大家在struts2中是怎么从jsp传list到后台的

wan368500 2012-05-28 03:16:16
先说下我的方法,也是捣鼓了一下:
action中:private List<Kpi> kpiLists2 ;


jsp中: <%int i= -1; %>
<s:iterator value="%{kpiLists}" var="kpi">
<%i++;%>
<tr>
<td><input name="kpiLists2[<%= i%>].keywords" value="${kpi.keywords }"/></td>
<td><input name="kpiLists2[<%= i%>].price" value="${kpi.price }"/></td>
<td><input name="kpiLists2[<%= i%>].showTimes" value="${kpi.showTimes }"/></td>
<td><input name="kpiLists2[<%= i%>].clickTimes" value="${kpi.clickTimes }"/></td>
<td><input name="kpiLists2[<%= i%>].clickRate" value="${kpi.clickRate }"/></td>
<td><input name="kpiLists2[<%= i%>].cost" value="${kpi.cost }"/></td>
<td><input name="kpiLists2[<%= i%>].averageCost"value="${kpi.averageCost }"/></td>
<td><input name="kpiLists2[<%= i%>].quailtyScore value="${kpi.quailtyScore }"/></td>
</tr>
</s:iterator>


Kpi类:
package com.yksuit.erp.taobao.promotion.data;

import java.util.Date;

/**
* Kpi entity. @author MyEclipse Persistence Tools
*/

public class Kpi implements java.io.Serializable {

// Fields

private Integer id;
private Product product;
private String keywords;
private Double price;
private Integer showTimes;
private Integer clickTimes;
private Double clickRate;
private Double cost;
private Double averageCost;
private Integer quailtyScore;
private Date date;

// Constructors

/** default constructor */
public Kpi() {
}

/** full constructor */
public Kpi(Product product, String keywords, Double price,
Integer showTimes, Integer clickTimes, Double clickRate,
Double cost, Double averageCost, Integer quailtyScore, Date date) {
this.product = product;
this.keywords = keywords;
this.price = price;
this.showTimes = showTimes;
this.clickTimes = clickTimes;
this.clickRate = clickRate;
this.cost = cost;
this.averageCost = averageCost;
this.quailtyScore = quailtyScore;
this.date = date;
}

// Property accessors

public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}

public Product getProduct() {
return this.product;
}

public void setProduct(Product product) {
this.product = product;
}

public String getKeywords() {
return this.keywords;
}

public void setKeywords(String keywords) {
this.keywords = keywords;
}

public Double getPrice() {
return this.price;
}

public void setPrice(Double price) {
this.price = price;
}

public Integer getShowTimes() {
return this.showTimes;
}

public void setShowTimes(Integer showTimes) {
this.showTimes = showTimes;
}

public Integer getClickTimes() {
return this.clickTimes;
}

public void setClickTimes(Integer clickTimes) {
this.clickTimes = clickTimes;
}

public Double getClickRate() {
return this.clickRate;
}

public void setClickRate(Double clickRate) {
this.clickRate = clickRate;
}

public Double getCost() {
return this.cost;
}

public void setCost(Double cost) {
this.cost = cost;
}

public Double getAverageCost() {
return this.averageCost;
}

public void setAverageCost(Double averageCost) {
this.averageCost = averageCost;
}

public Integer getQuailtyScore() {
return this.quailtyScore;
}

public void setQuailtyScore(Integer quailtyScore) {
this.quailtyScore = quailtyScore;
}

public Date getDate() {
return this.date;
}

public void setDate(Date date) {
this.date = date;
}

}

不知道大家还有没有更加好的方法,我这种方法是不得已而为之,望大家指教!
...全文
559 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yiweishuaige 2014-04-27
  • 打赏
  • 举报
回复
要传对象这样干 应该是比较好 要么你换成json传
sallyshero 2012-05-28
  • 打赏
  • 举报
回复
帮忙顶一下,虽然可能帮助不了什么。。共同学习学习~~楼主问题解决了记得说一声。共享
qq2511296 2012-05-28
  • 打赏
  • 举报
回复
input的name一样就可以了呀

<td><input name="kpiLists2" value="${kpi.keywords }"/></td>
<td><input name="kpiLists2" value="${kpi.keywords }"/></td>



String str[]=request.getParamerValues("kpiLists2")


这样就可以了吧。。。。。不知道LZ是不是想这样?
wan368500 2012-05-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
忘了说了,上面的遍历的kpiLists是传到jsp后展现的信息,kpiLists2是修改信息后传到后台的list集合,两个不同是一个集合,以上就是传到list的格式方法
tr>
<td><input name="kpiLists2[<%= i%>].keywords" value="${kpi.keywords }"/></td>
<td><input name="kpiLists2[<%= i%>].price" value="${kpi.price }"/></td>
<td><input name="kpiLists2[<%= i%>].……
[/Quote]
qiaowan19900712 2012-05-28
  • 打赏
  • 举报
回复
tr>
<td><input name="kpiLists2[<%= i%>].keywords" value="${kpi.keywords }"/></td>
<td><input name="kpiLists2[<%= i%>].price" value="${kpi.price }"/></td>
<td><input name="kpiLists2[<%= i%>].showTimes" value="${kpi.showTimes }"/></td>
<td><input name="kpiLists2[<%= i%>].clickTimes" value="${kpi.clickTimes }"/></td>
<td><input name="kpiLists2[<%= i%>].clickRate" value="${kpi.clickRate }"/></td>
<td><input name="kpiLists2[<%= i%>].cost" value="${kpi.cost }"/></td>
<td><input name="kpiLists2[<%= i%>].averageCost"value="${kpi.averageCost }"/></td>
<td><input name="kpiLists2[<%= i%>].quailtyScore value="${kpi.quailtyScore }"/></td>
</tr>
是为了什么?

684

社区成员

发帖
与我相关
我的任务
社区描述
智能路由器通常具有独立的操作系统,包括OpenWRT、eCos、VxWorks等,可以由用户自行安装各种应用,实现网络和设备的智能化管理。
linuxpython 技术论坛(原bbs)
社区管理员
  • 智能路由器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧