【发布时间】:2014-11-17 00:38:00
【问题描述】:
试图将ArrayList 从 java 类发送到 servlet。 ResultSet 的返回值被传递给模型对象,并且该对象被添加到ArrayList。但是我需要在vieitems.jsp 中检索这个ArrayList。
DBController.java
public void getAvailableItems(String sqlst) throws Exception {
Connection connection = getConnection();
Statement stm = connection.createStatement();
ResultSet rst = stm.executeQuery(sqlst);
ArrayList<Item> avitems = new ArrayList<Item>();
while (rst.next()) {
String itemname = rst.getString("ItemName");
String description = rst.getString("Description");
int qtyonhand = rst.getInt("QtyOnHand");
int reorderlevel = rst.getInt("ReorderLevel");
double unitprice = rst.getDouble("unitprice");
Item item = new Item(itemname, description, qtyonhand, reorderlevel, unitprice);
avitems.add(item);
}
//i need to send avitems to ViewItems.jsp
}
ViewItems.jsp
<form>
<Table border="1">
<tbody>
<tr> <td>Item Code</td><td>Item Name</td><td>Description</td><td> Qty On Hand</td><td>Reorder Level</td></tr>
//here i need to set the values of arraylist avitems
</tbody>
</Table>
</form>
【问题讨论】:
-
你知道
JSP吗? -
@PM77-1 在这里我试图将数组列表从 java 类传递给 jsp,而不是从 servlet 传递给 jsp。
-
你的 POJO 是什么的一部分?另外,您可能想回答我的第一个问题。这不是夸夸其谈。
-
我的第一条评论有一个 JSP 教程的链接。你可能想解决它。