javabean的错误

qwjlegend 2010-10-13 07:10:32
<%@ 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)

...全文
82 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
传值的类型不对吧???

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧