您的位置:首页 > 产品设计 > UI/UE

在使用JavaBean时遇到的问题:The value for the useBean class attribute is invalid

2010-04-16 23:07 851 查看
The value for the useBean class attribute is invalid ,

The value for the useBean class attribute java.lang.Integer is invalid.

The value for the useBean class attribute java.util.List is invalid

是因为在JSP中使用了代码:

<jsp:useBean id="ShowCharge" class="java.lang.Boolean" scope="request"/>

可能是JDK版本问题导致编译的时候找不到Boolean类。

怎么办呢?

在JSP页面:<jsp:useBean id="ShowCharge" class="java.lang.Boolean" scope="request"/>

会显示错误信息:The constructor Boolean() is undefined即没有对应的构造函数

实际上代码<jsp:useBean id="ShowCharge" class="java.lang.Boolean" scope="request"/>

等价于:

Boolean ShowCharge = (Boolean)request.getAttribute("ShowCharge");
if(ShowCharge == null){
Boolean ShowCharge = new Boolean();
request.setAttribute("ShowCharge",ShowCharge);
}

那么JDK1.6中是没有Boolean()构造函数的,所以会报错。。。。;

可见错误可能的原因包括:

1. 在编译 JSP 时(不是运行时),指定的 Bean 类没找到
2. Bean 虽然找到了,但是它不是 public 的,或者找到的 class 文件是 interface 或抽象类
3. Bean 类中没有 public 的默认构建函数

对于

The value for the useBean class attribute is invalid ,

解决方法,用等价代码去替换如
将:<jsp:useBean id="ShowCharge" class="java.lang.Boolean" scope="request"/>

替换成:

Boolean ShowCharge = (Boolean)request.getAttribute("ShowCharge");
if(ShowCharge == null){
Boolean ShowCharge = new Boolean(false );//注意这里换成带参数的构造方法
request.setAttribute("ShowCharge",ShowCharge);
}

对于

The value for the useBean class attribute java.lang.Integer is invalid.

解决方法,用等价代码去替换如

将:<jsp:useBean id="MaxDocDispIdx " class="java.lang.Integer" scope="request"/>

替换成:

Integer MaxDocDispIdx = (Integer)request.getAttribute("MaxDocDispIdx");
if(MaxDocDispIdx == null){
MaxDocDispIdx = new Integer(0);
request.setAttribute("MaxDocDispIdx",MaxDocDispIdx);
}

对于

The value for the useBean class attribute java.util.List is invalid

解决方法是将:

<jsp:useBean id="DocBeanList" class="java.util.List" scope="session" />

换成

<jsp:useBean id="DocBeanList" class="java.util.ArrayList" scope="session" />



经过测试发现另一种方法可以实现:

如:<jsp:useBean id="ShowCharge" class="java.lang.Boolean" scope="request"/>

改成<jsp:useBean id="ShowCharge" type="java.lang.Boolean" scope="request"/>

即将class 改成type.对以上Integer,List类型都可以。



还有对于class里的是一个object也可能是上诉情况。



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐