源代码如下:
<%@ page language=”java” import=”java.util.*”import=”java.sql.*” pageEncoding=”gbk”%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<base href=”<%=basePath%>”>
<title>test page</title>
</head>
<body>
<center><table border=1>
<tr><td>ID:</td><td>姓名:</td><td>电话:</td></tr>
<%
String driver=”com.mysql.jdbc.Driver”;
String url=”jdbc:mysql://localhost:3306/support”;
Class.forName(driver);
Connection con=DriverManager.getConnection(url, “root”, “123456”);
Statement cmd=con.createStatement();
String sql=”select * from customers”;
ResultSet rs=cmd.executeQuery(sql);
while(rs.next())
{
String Cid=rs.getString(1);
String Cname=rs.getString(2);
String Cphone=rs.getString(3);
out.println(“<tr> <td class=””id1″”>”+Cid+
“</td><td class=””id1″”>”+Cname+
“</td><td class=””id1″”>”+Cphone+
“</td></tr>”);
}
con.close();
%>
</table>
</center>
</body>
</html>
异常type Exception report
message An exception occurred processing JSP page /index.jsp at line 22
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 22
19: <%
20: String driver=”com.mysql.jdbc.Driver”;
21: String url=”jdbc:mysql://localhost:3306/support”;
22: Class.forName(driver);
23: Connection con=DriverManager.getConnection(url, “root”, “zxc123456″);
24: Statement cmd=con.createStatement();
25: String sql=”select * from customers”;
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.index_jsp._jspService(index_jsp.java:109)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:190)
org.apache.jsp.index_jsp._jspService(index_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.37 logs.
问题出在Class.forName(driver);这一句,但是我试了好久都没有解决,请大神来拯救一下我啊