一直提示/WebRoot/words_list_javabean.jsp(6,0) The value for the useBean class attribute com.zyj.splitPage is invalidwords_list_javabean.class放在D:\tomcat\webapps\ROOT\WebRoot\WEB-INF\classes\com\ch10下其中words_list_javabean.jsp代码如下
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ch10.*" %>
<jsp:useBean id="pages" scope="page" class="com.ch10.splitPage"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%!
//每页显示的记录数
int pageSize = 3;
String sqlStr="";
//当前页
int showPage=1;
//数据库用户名
String userName="root";
//数据库密码
String userPassword="admin";
    //数据库的URL,包括连接数据库所使用的编码格式
String url="jdbc:mysql://localhost:3306/zyj?useUnicode=true&characterEncoding=gb2312";
//定义连接对象
Connection dbcon;
%>
<%
try 
{
//加载驱动程序
Class.forName("org.gjt.mm.mysql.Driver");
//获得数据库的连接对象
dbcon= DriverManager.getConnection(url,userName,userPassword);
}
catch(SQLException ex)
{
//打印出异常信息
System.out.println(ex.toString());
}
catch(ClassNotFoundException ex)
{
//打印出异常信息
System.out.println(ex.toString());
} //给pages中参数con赋值
pages.setCon(dbcon);
sqlStr = "select * from words order by WordsID";
//查询数据表,获得查询结果
String strPage=null;
//获取跳转到的目的页面
strPage=request.getParameter("showPage");
if (strPage==null)
{
showPage=1;
}
else
{
try
{
showPage=Integer.parseInt(strPage);
}
catch(NumberFormatException e)
{
showPage = 1;
}
if(showPage<1) 
{
showPage=1;
}
}
pages.initialize(sqlStr,pageSize,showPage);
//获取要显示的数据集合
Vector vData=pages.getPage();
%>
<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>分页显示</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1 align=center>留言簿</h1>
<div align=center>
<table border="1" cellspacing="0" cellpadding="0" width="80%"> 
<tr> 
<th width="20%">编号</th> 
<th width="50%">留言标题</th> 
<th width="30%">留言时间</th> 
</tr>
<% 
for(int i=0;i<vData.size();i++)

//显示数据
String[] sData=(String[])vData.get(i);
%>
<tr> 
<td><%=sData[0]%></td> 
<td align=left><%=sData[1]%></td> 
<td align=left>
<%
//显示留言时间,省去时间串中"."后面的字符
String str_WordsTime = sData[3];
if(str_WordsTime.indexOf(".")>-1)
{str_WordsTime=str_WordsTime.substring(0,str_WordsTime.indexOf("."));
}
out.println(str_WordsTime);
%>
</td> 
</tr> 
<%
}
%>
</table>
<form action="words_list_javabean.jsp" method="get" target="_self">
共<font color=red><%=pages.getRowCount()%></font>条&nbsp;
<%=pageSize%>条/页&nbsp;
第<font color=red><%=showPage%></font>页/共<font 
color=red><%=pages.getPageCount()%></font>页 &nbsp;
<a href="words_list_javabean.jsp?showPage=1" target="_self">[首
页]</a>&nbsp;
<%
//判断"上一页"链接是否要显示
if(showPage > 1)
{
%>
<a 
href="words_list_javabean.jsp?showPage
=<%=showPage-1%>" target="_self">[上一页]</a>&nbsp;
<%
}
else
{
%>
[上一页]&nbsp;
<%
}
//判断"下一页"链接是否要显示
if(showPage < pages.getPageCount())
{
%>
<a 
href="words_list_javabean.jsp?showPage
=<%=showPage+1%>" target="_self">[下一页]</a>&nbsp;
<%
}
else
{
%>
[下一页]&nbsp;
<%
}
%> 
<a 
href="words_list_javabean.jsp?showPage
=<%=pages.getPageCount()%>" target="_self">[尾页]</a>&nbsp;
转到
<select name="showPage">
<%
for(int x=1;x<=pages.getPageCount();x++)
{
%>
<option value="<%=x%>" <%if(showPage==x) 
out.println("selected");%> ><%=x%></option>
<%
}
%>
</select>
页&nbsp;
<input type="submit" name="go" value="提交"/>
</form>
<%
//关闭数据库连接
dbcon.close();
%>
</div>
</body>
</html>其中splitPage.java代码如下
package com.ch10;
import java.sql.*;
import java.util.*;
public class splitPage
{
//定义数据库连接对象和结果集对象
private Connection con=null;
private Statement stmt=null;
private ResultSet rs=null;
private ResultSetMetaData rsmd=null;
//SQL查询语句
private String sqlStr;
//总记录数目
private int rowCount=0;
//所分的逻辑页数
private int pageCount=0;
//每页显示的记录数目
private int pageSize=0;
//设置参数值
public void setCon(Connection con)
{
this.con=con;
if (this.con == null)
{
System.out.println("Failure to get a connection!");
}
else
{
System.out.println("Success to get a connection!");
}
}
//初始化,获取数据表中的信息
public void initialize(String sqlStr,int pageSize,int ipage)
{
int irows = pageSize*(ipage-1);
this.sqlStr=sqlStr;
this.pageSize=pageSize;
try

stmt=this.con.createStatement(); 
rs=stmt.executeQuery(this.sqlStr);
if (rs!=null)
{
rs.last();
this.rowCount = rs.getRow();
rs.first();
this.pageCount = (this.rowCount - 1) / this.pageSize + 1; 

this.sqlStr=sqlStr+" limit "+irows+","+pageSize;
stmt=this.con.createStatement(); 
rs=stmt.executeQuery(this.sqlStr); 
rsmd=rs.getMetaData(); 


catch(SQLException e)
{
System.out.println(e.toString()); 

}
//将显示结果存到Vector集合类中
public Vector getPage()

Vector vData=new Vector();
try
{
if (rs!=null)
{
while(rs.next())
{
String[] sData=new String[6];
for(int j=0;j<rsmd.getColumnCount();j++)
{
sData[j]=rs.getString(j+1);
}
vData.addElement(sData);
}

rs.close(); 
stmt.close(); 

catch(SQLException e)
{
System.out.println(e.toString());


return vData; 

//获得页面总数
public int getPageCount()
{
return this.pageCount;
}
//获取数据表中记录总数
public int getRowCount()
{
return this.rowCount;
}
}

解决方案 »

  1.   

    应该是useBean没有找到class文件造成的,检查一下你的工程发布路径是不是D:\tomcat\webapps\ROOT\WebRoot\,因为目前你的class文件是放在默认路径下的,最好能放在你Web工程文件本身的WEB-INF下面。
    如果你有Eclipse的,可以选择让IDE帮你发布,这样会方便一些,而且路径也不会错
      

  2.   


    小弟新手,怎么检查工程的发布路径呢?class文件就是放在web-inf文件下面的,怎么让ide帮发布
      

  3.   

    你是用的Tomcat吧,一般来说发布的工程都会发布到Tomcat的webapps目录下面
    假设你的工程名字叫做examples,那么工程发布目录一般在:
    D:\tomcat-6.0.35\webapps\examples
    大概是这样。
    服务器启动以后,你需要用http://localhost:8080/examples来启动工程
    每一个工程文件都有自己的WEB-INF文件夹,里面放的是你这个工程需要使用的classes文件。工程和工程之间的classes一般是不共享的。如果用Eclipse的话,你可以新建一个Dynamic Web Project,然后在Eclipse里配置好服务器,然后选择Deploy功能,就能把工程自动发发布到你定义的服务器上了
      

  4.   


    恩,但是我就是搞不懂为什么一直这样显示/WebRoot/words_list_javabean.jsp(6,0) The value for the useBean class attribute com.zyj.splitPage is invalid
      

  5.   

    这个错误一般来说就是jsp:useBean无法找到对应的类,或者类里面没有定义缺省构造函数,或者对应类不是public,不过后两个问题貌似你这里不存在
      

  6.   

    splitPage  你是不是用的数字值啊?换成String看看
      

  7.   


    我用的是myeclipse,其中class="com.ch10.splitPage"说这句是未定义的类型,- 未定义类
     型:com.ch10.splitPage