jsp连接数据库tomcat在用usebean时异常!求救!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
我做了个jsp连接数据库的例子来测试我的tomcat服务器,用了javabean,但抛出了异常,错误如下:
希望大虾指教,谢谢哦。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a type
An error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a type
An error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a type
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
Apache Tomcat/5.5.9
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
其中jsp代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="jdbc" scope="page" class="Driver.jdbc"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>我要usebean!</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<% Connection con = jdbc.getConn() ;
Statement stmt = con.createStatement();
String strSQL = "select * from user";
ResultSet rs = stmt.executeQuery(strSQL);
while(rs.next())
{
String id = rs.getString("1");
String name = rs.getString("2");
%>
<tr>
<td width="95%" class="A">id=<%=id%> name=<%=name%>
<hr></td>
</tr>
<%
}
%>
</body>
</html>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
其中jdbc.class我放在了ub(本项目在webapps下)的\WEB-INF\classes\Driver下,即
C:\Tomcat 5.5\webapps\ub\WEB-INF\classes\Driver下
但不用usebean方式却可以正常访问,也可以调用数据库。
不管怎样,谢谢阅读。