Code Bye

关于javaee tomcat 网页编程

源代码如下:
<%@ 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);这一句,但是我试了好久都没有解决,请大神来拯救一下我啊

你导入mysql jar包没有,这个意思是驱动问题,你看看是否导入jar包先,如果导入了
你在看看你tomcat版本是不是有点低,之前遇见一个问题提示   jsp._jspService   这个错误,
最后把tomcat5.5版本换成了6 然后就搞定了
自己已经解决这个问题了,原来是因为tomcat中lib文件夹下没有mysql的驱动包,将jar的包复制到该文件夹下就可以了
引用 2 楼 u011295626 的回复:

自己已经解决这个问题了,原来是因为tomcat中lib文件夹下没有mysql的驱动包,将jar的包复制到该文件夹下就可以了

仅供大家参考


20分
因为tomcat中lib文件夹下没有mysql的驱动包,将jar的包复制到该文件夹下就可以了应该

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于javaee tomcat 网页编程