`

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类型都可以。

具体原因待查

分享到:
评论

相关推荐

    科技企业信息管理代码

    科技企业信息管理 ...The value for the useBean class attribute MD5.MD5 is invalid 猜测的话 useBean这个BEAN你没定义 自然他的属性MD5.MD5也就不存在了`` 好好看看你的WEB.XML等配置文件是不是少写了什么

    JSP Simple Examples

    This package is imported in the jsp page so that the Date class and its properties can accessed in the JSP page. If- Else Ladder A ladder means a vertical set of steps. It is a computer generated ...

    JSP useBean连接 Access 数据库,不使用数据源

    JSP useBean连接 Access 数据库,不使用数据源

    jsp事例jsp usebean session

    jsp设计事例jsp usebean session

    jsp+servlet+usebean实现MVC

    jsp+servlet+usebean实现MVC

    JSP+UseBean网上购书系统

    这是一个我自己用JSP+USEBEAN写的系统,

    usebean.jsp

    usebean.jsp

    jsp编程关于上传下载设计

    &lt;jsp:useBean id="updateBean" scope="page" class="guest.guest" /&gt; &lt;HTML&gt; &lt;BODY BGCOLOR="white"&gt; &lt;H1&gt;jspSmartUpload : Sample 2&lt;/H1&gt; &lt;HR&gt; String name = (String) session.getValue(...

    jsp音乐网源码

    &lt;input name="lrcUp" type="button" class="btn_grey" value="上传文件" disabled="none" onClick="if(this.form.fileURL.value!=''){window.open('upLrcFile.jsp?fileName='+this.form.fileURL.value,'','width=...

    jsp结合javabean的实践

    &lt;jsp:useBean id="rd" class="songyc.ReadFile" scope="application"&gt; &lt;jsp:setProperty name="rd" property="path" value="d:/testsongyc.txt" /&gt; &lt;/jsp:useBean&gt; HashMap hm=new HashMap(); Double db=null;...

    学习servlet,jsp,usebean,数据库封装的不错方法

    未完成的个人留言板,喜欢的接下去吧。本来是展示给最爱的师父的,可惜错过了,无限的遗憾,期待未完待续的结局 ,赫赫

    WebGIS的开发资料

    &lt;jsp:useBean id="connection"class="com.esri.aims.mtier.io.ConnectionProxy"scope="page"/&gt;&lt;jsp:useBean id="map"class="com.esri.aims.mtier.model.map.Map"scope="page"/&gt; connection.setConnectionType("tcp...

    jsp中文乱码问题jsp中文乱码问题详解

    对常见中文乱码问题进行了详细介绍和解释,希望能给大家以帮助。

    Jsp:useBean中字符串转化为Date类型的操作方法

    NULL 博文链接:https://zywang.iteye.com/blog/412922

    regedit.jsp 表单注册用户名密码

    &lt;jsp:useBean id="query" class="Bean.QueryBean" scope="session"&gt; *"/&gt; &lt;/jsp:useBean&gt; request.setCharacterEncoding("UTF-8"); String name=request.getParameter("username"); String password=request....

    jspSmartUpload上传下载

    &lt;jsp:useBean id="jdbc" class="com.Jdbc_conn" scope="page" /&gt; (); java.util.Date todayime = new java.util.Date(today); SimpleDateFormat formatter = new SimpleDateFormat("yyMMddHHmmss"); String ...

    JSP数据库操作例程(Use Bean)

    – 数据分页显示 – JDBC 2.0:ODBC 通过jdbc:odbc可以实现Jsp对数据库的操作,在这个例子中我将数据库的连接写在了一个JavaBean中,可以实现重复使用 pagetest.jsp文件: &lt;!...&#37;...jsp:useBean id=

    spring技术入门相关源码

    public class SpringTest { public static void main(String[] args) { //创建spring的ApplicationContext ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); //...

    jsp标准动作

    详细介绍了jsp标准动作各个标记及其属性的使用方法。

    课程设计(JSP)代码第2章

    &lt;jsp:useBean id="db" class="dbBean.DBBean" scope="session"/&gt; &lt;jsp:setProperty name="db" property="connStr" value="jdbc:odbc:vote"/&gt; &lt;html&gt;&lt;body&gt; 您最喜爱的奥斯卡获奖影片是: ResultSet rs=db....

Global site tag (gtag.js) - Google Analytics