試圖從java類發送ArrayList
到servlet。將ResultSet
的返回值傳遞給模型對象,並將此對象添加到ArrayList
。不過,我需要在vieitems.jsp
中檢索這個ArrayList
。如何將ArrayList從Java類傳遞到jsp
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'](http://beginnersbook.com/category/jsp-tutorial/)的任何內容嗎? – 2014-09-22 23:10:25
[Pass from servlet to jsp variables](http://stackoverflow.com/questions/3608891/pass-variables-from-servlet-to-jsp) – 2014-09-22 23:16:37
@ PM77-1這裏我試圖通過一個從java類到jsp的arraylist,而不是從servlet到jsp。 – 2014-09-22 23:33:18