JSTL没有在JavaBean中找到属性

时间:2013-04-15 14:29:57

标签: java jsp exception jstl

我遇到的问题与此堆栈溢出问题JSP not finding property in bean非常相似。还有这个问题javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean。然而在我的情况下,我认为我已经完成了所有的书籍,我仍然得到一个错误。 以下是我的javabean代码段的一部分

    private double otheramount;
    private int no;
    private String name;


        public double getOtherAmount()
            {
                return otheramount;
            }
            public void setOtherAmount(double newotheramount)
            {
                otheramount = newotheramount;        
            }
public int getNo()
            {
                return no;
            }
            public void setNo(int newno)
            {
                no = newno;        
            }
public String getName()
            {
                return name;
            }
            public void setName(String newname)
            {
                name = newname;        
            }

以下是我的DAO代码的一部分

while(rs.next())
         {

              MyBean mybean = new MyBean();

              mybean.setNo(rs.getInt("No"));
              mybean.setName(rs.getString("Full_Names"));              
              mybean.setOtherAmount(rs.getDouble("OtherAmount"));              

              allresults.add(mybean);



         }

以下是servlet代码的一部分

try
{
ArrayList allresults = mydao.search();    
request.setAttribute("allresults",allresults);
RequestDispatcher dispatch =request.getRequestDispatcher("Pages/mypage.jsp");
dispatch.forward(request, response);
}
catch(Exception ex)
{
}

以下是我在JSP页面中的HTML和JSTL代码

<c:forEach var="results" items="${requestScope.allresults}">
  <tr>
    <td><c:out value="${results.no}"></c:out></td>
    <td><c:out value="${results.name}"></c:out></td>
    <td><c:out value="${results.otheramount}"></c:out></td>
  </tr>
</c:forEach>

问题在于,当我评论部分<c:out value="${results.otheramount}"></c:out>时,它运行正常并且不会抛出任何错误。但是,取消注释此部分会导致找不到属性的错误。 作为旁注,财产otheramount很晚才被添加。

我正在使用Netbeans 7.1.2。任何帮助非常感谢。

1 个答案:

答案 0 :(得分:6)

不会根据私有字段名称解析Bean属性名称。相反,它们是基于getter方法名称解析的。

在您的特定情况下,属性名称不是otheramount,而是otherAmount

另见:

相关问题