日期:2014-05-17  浏览次数:20751 次

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这样的,不然是不能得到的。