JSTL没有在JavaBean中找到属性 [英] JSTL not finding a property in a JavaBean

查看:310
本文介绍了JSTL没有在JavaBean中找到属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题非常类似于此堆栈溢出问题 JSP找不到属性在豆子里。还有这个问题 javax.el.PropertyNotFoundException:在com.example.Bean类型上找不到属性'foo'。然而在我的情况下,我认为我已经完成了所有的书籍,我仍然得到一个错误。
以下是我的javabean代码段的一部分

I have a problem that is very similar to this stack overflow question JSP not finding property in bean. And also this question javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean. However in my case I think that i have done everything by the books and I am still getting an error. Below is part of my javabean code snippet

    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在很晚之后被添加。

The problem is that when I comment the part <c:out value="${results.otheramount}"></c:out> it runs okay and no errors are thrown. However uncommenting this part results in the error of property not found. As a side note, the property otheramount was added much later.

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

I am using Netbeans 7.1.2. Any help greatly appreciated.

推荐答案

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

Bean property names are not resolved on basis of private field names. Instead, they are resolved on basis of getter method names.

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

In your particular case, the property name is thus not otheramount, but it is instead otherAmount.

  • JavaBeans specification
  • JavaBeans tutorial

这篇关于JSTL没有在JavaBean中找到属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆