我在netbeans中编写了这段代码,我的本地服务器(Netbeans)可以成功运行
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1><%
try{
Class.forName("org.gjt.mm.mysql.Driver"); //Load the driver
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/dbname", "dbuser", "password"); //Connect
ResultSet rs = conn.createStatement().executeQuery("SELECT `name` FROM `people`");
while (rs.next() == true){
out.println(rs.getString("name"));
}
}
catch (Exception err){
out.println(err.toString());
}
%></h1>
</body>
</html>
但是当我尝试在我的服务器中运行时,我收到了这个错误
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
Mysql jar 文件位于 WEB-INF/lib 文件夹中,它在本地服务器上运行良好。