javax.el.PropertyNotFoundException: Property ‘xxx‘ not found on type bean

遇到的问题:
在使用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页面中的属性名称。就可以访问成功了。
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值