在jsp中引用javaBean的属性时报错(是一个老问题了,可查了很多资料,不能对症),报错信息如下:Cannot find any information on property 'Product' in a bean of type 'test.testbean';
javaBean源码如下(testbean.java)(testbean.class可正常编译,也放入了正确的位置):
package test;
public class testbean
{
  public String Product;
  public double Price;
  public testbean()
  {
    this.Product="guitar";
    this.Price=200.0;
  }
  public void setProduct(String ProductName)//此处曾将形参变量改为Product,product都不行
  {
    this.Product=ProductName;
  }
  public String getProduct()
  {
    return(this.Product);
  }
  public void setPrice(double ProductPrice)//此处同上
  {
    this.Price=ProductPrice;
  }
  public double getPrice()
  {
    return (this.Price);
  }
}
jsp源码如下(testBean.jsp)(为方便查看,去掉了html部分的代码):
<jsp:useBean id="testbean" scope="application" class="test.testbean"/>
第一种显示方式:(可正常显示)
<%
 testbean.setProduct("car");
 testbean.setPrice(200000.0);
%>
ProductName:<%=testbean.getProduct()%>
ProductPrice:<%=testbean.getPrice()%>
第二种显示方式:(不能正常显示)
<jsp:setProperty name="testbean" property="Product" value="testcar"/><!--此处报错,说找不到testbean类的Product相关属性-->
<jsp:setProperty name="testbean" property="Price" value="100000.0"/>
ProductName1:<jsp:getProperty name="testbean" property="Product" /><!--此处也报类似错误-->
ProductPrice1:<jsp:getProperty name="testbean" property="Price" />
已经多次调试,还是不能找到出错原因,请各位同志,学长指点,先谢谢了。

解决方案 »

  1.   

    你把你bean中的属性public String Product改成public String product;重新试试,应该可以.
      

  2.   

    将public String Product改成public String product;就可以了!
      

  3.   

    果然英雄所见略同,受各位学长的启发,程序终于调试成功了,谢谢大家了!!很抱歉没有及时回帖,因为从中午一直调试到现在,中间又出现了新的问题,但都一一解决了,在此跟大家分享一下经验:
    1.本帖问题的解决方法:也许跟我机器的环境有关,按照各位学长的指点,我把public String Product改成public String product,然后将testBean.jsp中的property="Product"(相关语句)改为property="product"(如果不改jsp中的这些语句则程序不能正常运行)就可以正常运行程序了,然后又试着将public String product改成public String Product,程序仍可以正常运行,结论就是:jsp页面中的property="product"等相关属性值必须是 小写。2.本帖之外的新问题及解决办法:反复的调试发现jsp中的注释语句中的property="product"等相关属性值也不能是大写的,即不可写成property="Product",虽然是在注释语句中。例如:
    <!--
    ProductName1:<jsp:getProperty name="testbean" property="Product" />
    ProductPrice1:<jsp:getProperty name="testbean" property="Price" />
    -->
    仍然会编译出错,也许还跟我的系统环境(jdk1.5.0_04+Tomcat6.0+SqlServer2005)有关系,总之这两个问题的本质原因我还是不太清楚,究竟系统内部是如何编译,执行代码的,我也不清楚,呵呵……还好问题总算解决了,虽然花了很长时间,不过要不是大家的帮助,可能会用去更多的时间,再次谢谢大家的帮助!!!