无法在我的显示标记中获取bean的值..显示以下错误
String sql;
List<AcceptBean> list = new ArrayList<AcceptBean>();
PreparedStatement prest = (PreparedStatement) conn.prepareStatement(occQuery);
ResultSet rs = prest.executeQuery(occQuery);
System.out.println(rs);
String first = "";
String last = "";
String vill = "";
String son = "";
String dist = "";
while (rs.next()) {
AcceptBean bean = new AcceptBean();
bean.setFirstName(rs.getString("FirstName"));
bean.setLastName(rs.getString("LastName"));
bean.setVillage(rs.getString("Village"));
bean.setSonOf(rs.getString("SonOf"));
bean.setDistrict(rs.getString("District"));
list.add(bean);
}
// list.add(objBean);
System.out.println("list vlues in servelet" + list.get(0));
System.out.println("list detials inserted");
request.setAttribute("list1", list);
ServletContext context = getServletContext();
RequestDispatcher rd = context.getRequestDispatcher("/Report.jsp");
System.out.println("request dispatched");
rd.forward(request, response);
这是我的jsp代码
<display:table name="requestScope.list1" >
<display:column property="firstname" title="First Name"></display:column>
<display:column property="lastname" title="Last Name" ></display:column>
<display:column property="sonof" title="Father's Name" ></display:column>
<display:column property="district" title="District" ></display:column>
<display:column property="village" title="Village" ></display:column>
</display:table>
错误 例外:[。LockupUtil]在对象类型“ColdStorage.AcceptBean”中查找属性“firstname”时出错。原因:类'ColdStorage.AcceptBean'上的未知属性'firstname'
答案 0 :(得分:0)
当然。如果您不能在其中放置对象,那么列表的重点是什么?它应该声明并初始化为
List<AcceptBean> list = new ArrayList<AcceptBean>
虽然。
问题在于您告诉标记在名为“list”的请求属性中查找列表,但它存储在名为“list1”的请求属性中。
就像你一样,当然你应该在wile循环中创建一个新的AcceptBean,并将它添加到while循环内的列表中。否则,您的列表中只有一个对象,包含从数据库中检索到的最后一行:
List<AcceptBean> list = new ArrayList<AcceptBean>();
PreparedStatement prest = (PreparedStatement) conn.prepareStatement(occQuery);
ResultSet rs = prest.executeQuery();
while (rs.next()) {
AcceptBean bean = new AcceptBean();
bean.setFirstName(rs.getString("FirstName"));
bean.setLastName(rs.getString("LastName"));
bean.setVillage(rs.getString("Village"));
bean.setSonOf(rs.getString("SonOf"));
bean.setDistrict(rs.getString("District"));
list.add(bean);
}
request.setAttribute("list1", list);
没有。你为什么不读标签文件?它解释了如何使用它,属性是什么,并包含大量示例。
见上文。