I am trying to populate a JSP table with the contents of a HashMap, but I keep getting PropertyNotFoundExceptions on the first attempt to reference it in the JSP (the firstName property). I have tried using the var['key'] and the var.value.key way of referencing it in EL and every time I get a PropertyNotFoundException. Here's the code I'm using:
The JSP:
<c:forEach var="orders" items="${ orderList }">
<tr>
<td class="name">
<a href="">${ orders.firstName }</a>
</td>
<td>${ orders.date }</td>
<td>${ orders.product }</td>
<td>${ orders.comments }</td>
</tr>
</c:forEach>
The Servlet that sets the attribute:
FormManager fm = new FormManager();
HashMap hm = fm.getOrder();
request.setAttribute("orderList", hm);
From the FormManager class:
public HashMap getOrder() {
dbm = new DatabaseManager();
Statement stmt = null;
String sql = "SELECT * FROM orders";
HashMap<String, String> itemMap = new HashMap<String, String>();
String[] keys = { "firstName", "lastName", "phone", "email" , "date", "product", "comments", "id" };
dbm.setUrl("jdbc:mysql://localhost:3306/pattycakes");
dbm.connect();
try {
stmt = dbm.getConn().createStatement();
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
int columns = rsmd.getColumnCount();
for (int i = 0; i < columns; i++) {
rs.beforeFirst();
rs.next();
itemMap.put(keys[i], rs.getString(i + 1));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
dbm.disconnect(stmt, dbm.getConn());
}
return itemMap;
}
There may be some issues with that code so far, because I am still in the process of writing this for a family member. All I'm concerned with is how to get past the exception. Thanks!