首页 > 代码库 > The value for the useBean class attribute is invalid

The value for the useBean class attribute is invalid

最近,在看Pro JSP2这本书,37页的Listing 1-9是一个简单的例子。但是把所有的代码都打完了,但奇怪的错误出现了。

The value for the useBean com.apress.projsp.DateFormatBean attribute is invalid。

在网页找了很久,发现这个文章有技术含量。但, it doesn‘t work。

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

 

原来是我设置tomcat的context不对。

错误:我把dateBean.jsp文件放到view文件夹中。tomcat的document base:.../WebContent/WEB-INF/view/ path为/chp01

在浏览器中输入:http://localhost:8080/chp01/dateBean.jsp

改正:把dateBean.jsp文件放到WebContent文件夹下。tomcat的document base:.../WebContent

在浏览器中输入:http://localhost:8080/chp01/dateBean.jsp

 

下面是文件:

dateBean.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Professional JSP 2.1</title> 8 </head> 9 <body>10     <jsp:useBean id="date" class="com.apress.projsp.DateFormatBean"/>11     <h2>Today‘s Date is <%=date.getDate() %></h2>12 </body>13 </html>
DateFormatBean.java
package com.apress.projsp;import java.text.*;import java.util.Date;public class DateFormatBean {    private DateFormat dateFormat;    private Date date;    public DateFormatBean(){        dateFormat = DateFormat.getInstance();        date = new Date();    }        public String getDate(){        return dateFormat.format(date);    }        public void setDate(Date date){        this.date = date;    }        public DateFormat getDateFormat(){        return this.dateFormat;    }        public void setFormat(String format){        this.dateFormat = new SimpleDateFormat(format);    }}

新手刚入行,未能深入浅出。请多多指点,谢谢!

 

 

The value for the useBean class attribute is invalid