遇到的问题:
在使用Idea开发Java Web时,调用Session域中的数据和Java Bean显示在jsp页面中出现了如下错误:
但是我的类中已经定义了geter和seter方法,如下:
/*
购物车的商品项
*/
public class CartItem {
private Integer id;
private String name;
private Integer count;
private BigDecimal price;
private BigDecimal totalPrice;
public CartItem(Integer id, String name, Integer count, BigDecimal price, BigDecimal totalPrice) {
this.id = id;
this.name = name;
this.count = count;
this.price = price;
this.totalPrice = totalPrice;
}
public CartItem() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
***~~public BigDecimal getTotalprice() {
return totalPrice;
}
public void setTotalprice(BigDecimal totalprice) {
this.totalprice = totalPrice;
}~~ ***
@Override
public String toString() {
return "CartItem{" +
"id=" + id +
", name='" + name + '\'' +
", count=" + count +
", price=" + price +
", totalPrice=" + totalPrice +
'}';
}
}
而Jsp中的调用代码是通过EL实现,也导入了相应的包。因为其他属性是可以正常显示值的,也可以排除是jsp页面代码问题。如下:
有人说是bean的属性名称错误,或者没有getter,setter方法,但是我的bean如下方法。
又参考错误 javax.el.PropertyNotFoundException: Property ‘totalPrice’ not found on type com.atguigu.pojo.CartItem
建议你将这属性的名称改为小写:
下面是我自己总结的方法:
属性命名最好是小写的,当然首字母一定要小写。上面出问题的属性名称为totalPrice,我之后把CartItem这个类中的该属性名称改为了totalprice,同时修改Jsp页面中的属性名称。就可以访问成功了。