The value for the useBean class attribute is invalid 问题

程序由JDK1.3升级到JDK1.6的时候,使用ANT预编译JSP时提示:

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()构造函数的,所以会报错。。。。;

以下相关链接对这个问题进行了分析,很不错的。

 

查找以下链接及相关:

http://www.blogjava.net/bluesky/archive/2005/12/05/22600.html

http://www.cnblogs.com/feiweiwei/archive/2007/12/05/984484.html

引用:--

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

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" />

关于The value for the useBean class attribute java.util.List is invalid这个问题可参见:

http://www.coderanch.com/t/286029/JSP/java/error-value-useBean-class-attribute

 

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

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

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

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

具体原因待查

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值