1

无法在我的显示标签中获取 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>

错误异常:[.LookupUtil] 在对象类型“ColdStorage.AcceptBean”中查找属性“firstname”时出错。原因:类'class ColdStorage.AcceptBean'上的未知属性'firstname'

4

1 回答 1

0
  1. 当然。如果您不能将对象放入其中,那么列表的意义何在?它应该被声明和初始化为

    List<AcceptBean> list = new ArrayList<AcceptBean> 
    

    尽管。

  2. 问题是您告诉标签在名为“list”的请求属性中查找列表,但它存储在名为“list1”的请求属性中。

  3. 就像您所做的那样,当然您应该在 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);
    
  4. 不。你为什么不阅读标签文档?它解释了如何使用它,属性是什么,并包含大量示例。

  5. 往上看。

于 2013-03-05T22:36:58.287 回答