こんにちは私はjspに不慣れで、mysqldbからいくつかのデータを表示しようとしていました。そのために、Tomcat 7サーバーにコネクタとしてJDK1.7、MySQL Server 5.5、mysql-connector-java-5.1.19-bin.jarをインストールしました。%CATALINA_HOME%webapps / ROOT / ws /フォルダー、つまりindex.jspにコードを含むファイルを作成しました
<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost:test?user=root;password=sumant";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
<html><body>
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "", "");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT name FROM store");
while (rs.next()) {
out.println(rs.getString("name")+"<br>");
}
rs.close();
%>
</body></html>
そして、URLを呼び出すと:http:// localhost:8080 / ws/index.jsp私は得ています
HTTP Status 500 -
type Exception report
message
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 /ws/index.jsp at line 14
11:
12:
13: <%
14: Class.forName("org.gjt.mm.mysql.Driver").newInstance();
15: connection = DriverManager.getConnection(connectionURL, "", "");
16: statement = connection.createStatement();
17: rs = statement.executeQuery("SELECT name FROM store");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:456)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.ws.index_jsp._jspService(index_jsp.java:98)
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:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.ws.index_jsp._jspService(index_jsp.java:78)
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:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
今、私はここで何が悪いのかわかりません。mysqlデータベースへの接続を手伝ってください。ありがとう。