我正在尝试将我的JSP登录文件链接到MySQL数据库,但是我收到的错误如下所示。我还将MySQL-connector jar文件导入到项目中。我不知道为什么我会收到这个错误。请帮我纠正我的错误。
我的代码:
<%@ page import ="java.sql.*" %>
<%
String userid = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/college",
"root", "root");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from studentdata where uname='" + userid + "' and pass='" + pwd + "'");
if (rs.next()) {
session.setAttribute("userid", userid);
//out.println("welcome " + userid);
//out.println("<a href='logout.jsp'>Log out</a>");
response.sendRedirect("success.jsp");
} else {
out.println("Invalid password <a href='index.jsp'>try again</a>");
}
%>
错误讯息:
type Exception report
message An exception occurred processing JSP page /login.jsp at line 5
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 /login.jsp at line 5
2: <%
3: String userid = request.getParameter("uname");
4: String pwd = request.getParameter("pass");
5: Class.forName("com.mysql.jdbc.Driver");
6: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/college",
7: "root", "root");
8: Statement st = con.createStatement();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
答案 0 :(得分:1)
您收到此错误:
java.lang.ClassNotFoundException:com.mysql.jdbc.Driver
建议:
1.-是WEB-INF / lib文件夹中的驱动程序mysql ****。jar?
2.-你是否在课程路径中注册了它?
希望有所帮助