【JavaBean错误】Cannot find a method to write property [类型] of type [类型] in a bean of type

1 篇文章 0 订阅
1 篇文章 0 订阅

在JavaBean的setter方法中,要求setXXX(ClassType xXX)的参数与XXX变量的类型ClassType一致,否则报错:

Cannot find a method to write property [类型] of type [类型] in a bean of type 

Eg:举一个错例

(1)JavaBean定义:(注意setter方法是错的)

package com.question;

public class Demo {
    private int index;

    public void setIndex(String index) {  // 注意:正确的参数应该是int index
        this.index = 100;  // 这里不准备用传入的参数赋值
    }

    public int getIndex() {
        return index;
    }
}

(2)在jsp页面使用JavaBean:(这里是正确写法)

<jsp:useBean id="demo" class="com.question.Demo"/>
<jsp:setProperty name="demo" property="index" value="4444"/>
<jsp:getProperty name="demo" property="index"/>

(3)运行报错:

Type Exception Report

Message Cannot find a method to write property [index] of type [int] in a bean of type [com.question.Demo]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

(4)解决方法:

将JavaBean的setter方法修正即可

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值