我是jsp的初学者,我试图从数据库中列出用户,这是我的代码:
登录.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="java.io.*,java.util.*,java.sql.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>InfoVisual</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
</head>
<body>
<sql:setDataSource var="chh_cw" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/chh-cw"
user="root" password="1234"/>
<sql:query dataSource="${chh_cw}" var="result">
select DispUserName from user_mst;
</sql:query>
<table border="1" width="100%">
<tr>
<th>District</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.DispUserName}"/></td>
</tr>
</c:forEach>
</table>
<form method="post" action="Login">
<div class="login">
Select District
<select name="district">
</select>
<br />Username <input type="text" name="username"/>
<br />Password <input type="password" name="pswd"/>
<br /><input type="submit" name="submit" value="Login"/>
</div>
</form>
</body>
</html>
我提到了网站tutorialspoint:http ://www.tutorialspoint.com/jsp/jsp_database_access.htm
但我收到了这个错误(它很长,很抱歉):
org.apache.jasper.JasperException: An exception occurred processing JSP page /Login.jsp at line 17
14: <link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
15: </head>
16: <body>
17: <sql:setDataSource var="chh_cw" driver="com.mysql.jdbc.Driver"
18: url="jdbc:mysql://localhost/chh-cw"
19: user="root" password="1234"/>
20: <sql:query dataSource="${chh_cw}" var="result">
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:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: In <driver>, invalid driver class name: "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:908)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.Login_jsp._jspService(Login_jsp.java:126)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:270)
org.apache.taglibs.standard.tag.common.sql.DataSourceWrapper.setDriverClassName(DataSourceWrapper.java:55)
org.apache.taglibs.standard.tag.common.sql.SetDataSourceTagSupport.doStartTag(SetDataSourceTagSupport.java:111)
org.apache.jsp.Login_jsp._jspx_meth_sql_005fsetDataSource_005f0(Login_jsp.java:152)
org.apache.jsp.Login_jsp._jspService(Login_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
这是我的项目结构:
抱歉这个问题太长了。请指导我解决这个问题。谢谢:)