我想知道为什么我的迭代器只显示了我的jsp的一个结果。这是我在s:iterator中的代码:
<s:iterator value="origins" var="items">
<s:select list="#items" label="Select origin" name="origin">
</s:select>
</s:iterator>
这是我的行动代码:
public class QueryAction{
private Sector sectorBean = null;
private List<String> origins;
private List<String> destinations;
public List<String> getOrigins() {
return origins;
}
public void setOrigins(List<String> origins) {
this.origins = origins;
}
public List<String> getDestinations() {
return destinations;
}
public void setDestinations(List<String> destinations) {
this.destinations = destinations;
}
public String listing() {
SectorDA sda = new SectorDAImpl();
origins = sda.getOrigins();
destinations = sda.getDestinations();
return "success";
}
}
原籍和目的地的价值分别是:纽约,新奥尔良,密歇根,孟菲斯,芝加哥和匹兹堡。两者都只显示了芝加哥。任何人都可以帮助我吗?
-UPDATE -
我发现为什么迭代器只显示一个结果。这是因为班级'相应的DA。以下是代码:
private static final String GET_ALL_SECTORS = "SELECT cSectorId, cOrigin, cDestination, cWeekDay1, cWeekDay2, mFirstClassFare, mBusinessClassFare, mEconomyClassFare FROM Sector";
@Override
public List<Sector> getAllSectors() {
List<Sector> sectors = new ArrayList<Sector>();
Statement stat = null;
try {
stat = DatabaseConnector.getConnection().createStatement();
ResultSet rs = stat.executeQuery(GET_ALL_SECTORS);
if(rs.next()) {
String sectorId = rs.getString(1);
String origin = rs.getString(2);
String destination = rs.getString(3);
String weekDay1 = rs.getString(4);
String weekDay2 = rs.getString(5);
BigDecimal fcFare = rs.getBigDecimal(6);
BigDecimal bcFare = rs.getBigDecimal(7);
BigDecimal ecFare = rs.getBigDecimal(8);
Sector e = new Sector(sectorId, origin, destination, weekDay1, weekDay2, fcFare, bcFare, ecFare);
sectors.add(e);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(stat != null) {
try {
stat.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return sectors;
}
请帮帮我。