当前位置: 代码迷 >> Java Web开发 >> struts2怎样接收多个重名参数解决方案
  详细解决方案

struts2怎样接收多个重名参数解决方案

热度:1267   发布时间:2013-02-25 21:18:18.0
struts2怎样接收多个重名参数
HTML code
<div class="hotel">   <input name="hotel.name" type="text">   <input name="hotel.area" type="text">   <input name="hotel.stars" type="text">   <input name="hotel.roomType" type="text">   <input name="hotel.checkin" type="text">   <input name="hotel.checkout" type="text"></div><div class="hotel">   <input name="hotel.name" type="text">   <input name="hotel.area" type="text">   <input name="hotel.stars" type="text">   <input name="hotel.roomType" type="text">   <input name="hotel.checkin" type="text">   <input name="hotel.checkout" type="text"></div><div class="hotel">   <input name="hotel.name" type="text">   <input name="hotel.area" type="text">   <input name="hotel.stars" type="text">   <input name="hotel.roomType" type="text">   <input name="hotel.checkin" type="text">   <input name="hotel.checkout" type="text"></div>


实体类是Hotel.java
Java code
public class Hotel {        private int id;    private String name;    private String area;    private String stars;    private String roomType;    private Date checkin;    private Date checkout;    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getArea() {        return area;    }    public void setArea(String area) {        this.area = area;    }    public String getStars() {        return stars;    }    public void setStars(String stars) {        this.stars = stars;    }    public String getRoomType() {        return roomType;    }    public void setRoomType(String roomType) {        this.roomType = roomType;    }    public Date getCheckin() {        return checkin;    }    public void setCheckin(Date checkin) {        this.checkin = checkin;    }    public Date getCheckout() {        return checkout;    }    public void setCheckout(Date checkout) {        this.checkout = checkout;    }}



请问怎样全部接收,然后写进数据库,并且数据库中的记录有3条?

------解决方案--------------------------------------------------------
request直接提供函数的:
String[] getParameterValues(name)

可以得到一个String[] 数组
------解决方案--------------------------------------------------------
用struts得到的话,像你的这种传值方式,必须是obj[i].attr这样的,不然是不能得到的。
  相关解决方案