I have this Bean
public class Bank {
private String id;
private String bankname;
public void setId(String id){
this.id = id;
}
public void setBankname(String name){
this.bankname = name;
}
public String getId(){
return id;
}
public String getBankname(){
return bankname;
}
And also A Servlet that receiving an ArrayList taken from MySQL. This arraylist is using that Bean I mentioned earlier.
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
int manyRow = 15;
ArrayList<Bank> bankList = new MysqlUtil().getBankTableData(15);
HttpSession sess = request.getSession(true);
try {
sess.setAttribute("susunan", bankList);
sess.setAttribute("panjang", bankList.size());
request.getRequestDispatcher("table/bankTable.jsp").forward(request, response);
return;
} finally {
out.close();
}
And this is my JSP accessing them by iterating it:
<table width="100%" border="0">
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<c:forEach items="${susunan}" var="bankData">
<tr>
开发者_C百科 <td><c:out value="${susunan.id}"></c:out></td>
<td><c:out value="${susunan.bankname}"></c:out></td>
</tr>
</c:forEach>
</table>
But the result I got is
ERROR for input string : "id" and for input string : "bankname"
Why does the JSP seem to not recognize my bean?
<c:forEach items="${susunan}" var="bankData">
<tr>
<td><c:out value="${bankData.id}"></c:out></td>
<td><c:out value="${bankData.bankname}"></c:out></td>
</tr>
</c:forEach>
The variable named susanan is the entire list; it does not have an id. The variable named bankData is the individual beans.
精彩评论