javabean的错误
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
<jsp:useBean id="contact" class="qwj.ContactBean" scope="page"/>
<html>
<body>
<center>
使用JavaBean来操作数据库:<hr>
<%
try
{
ResultSet rst=contact.getContact(1);
%>
<table border=1>
<tr>
<td width=100>productid</td>
<td width=100>productname</td>
</tr>
<%
while(rst.next()){
%>
<tr>
<td><%=rst.getInt(1)%></td>
<td><%=rst.getString(2)%></td>
</tr>
<%}%>
</table>
<%
rst.close();
}
catch(SQLException el){}
%>
</center>
</body>
</html>
package qwj;
import java.sql.*;
public class ContactBean
{
private Connection con;
//初始化连接。
public ContactBean()
{
String CLASSFORNAME="sun.jdbc.odbc.JdbcOdbcDriver";
String SERVANDDB="jdbc:odbc:nt";
String USER="sa";
String PWD="";
try
{
Class.forName(CLASSFORNAME).newInstance();
con = java.sql.DriverManager.getConnection(SERVANDDB,USER,PWD);
}
catch(Exception e)
{
e.printStackTrace();
}
}
//查询数据库
public ResultSet getContact(int productid)
{
try
{
Statement stm=con.createStatement();
ResultSet rst=stm.executeQuery
("select productid,productname from products where productid='"+productid+"'");
return rst;
}
catch(Exception e)
{
}
return null;
}
}
报错是:HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /useBean.jsp(2,0) The value for the useBean class attribute qwj.ContactBean is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1200)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1155)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Generator.generate(Generator.java:3394)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:210)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)