<%@page import="org.json.JSONObject"%>
<%@page import="java.lang.Thread.State"%>
<%@page import="net.sf.json.JSONArray"%>
<%@ page language="java" import="java.io.*,java.sql.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
String mySqlUrl = "jdbc:mysql://localhost:3306/permit";
Connection con = DriverManager.getConnection(mySqlUrl ,"root","moodle123");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from enterprisemaster where `enterpriseId=1001");`
JSONArray respJson = new JSONArray();
java.sql.ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount();
while (rs.next()) {
JSONObject obj = new JSONObject();
for (int i = 1; i < numColumns + 1; i++) {
String columnName = rsmd.getColumnName(i);
obj.put(columnName, rs.getString(columnName));
}
respJson.put(obj);
}
respJson.toString();
System.out.println(respJson);
}
catch(Exception e)
{
System.out.println(e);
}
%>
</body>
</html>
類型異常報告Java代碼來創建JSON數組
message An exception occurred processing JSP page /JsonCreation.jsp at line 36
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
/JsonCreation.jsp at line 36
33: obj.put(columnName, rs.getString(columnName));
34:
35: }
36: respJson.put(obj);
37: }
38: respJson.toString();
39: System.out.println(respJson);
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:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
root cause
javax.servlet.ServletException: java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.JsonCreation_jsp._jspService(JsonCreation_jsp.java:119)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
root cause
java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
net.sf.json.JSONArray.put(JSONArray.java:1296)
org.apache.jsp.JsonCreation_jsp._jspService(JsonCreation_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
root cause
java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
net.sf.json.JSONArray.put(JSONArray.java:1296)
org.apache.jsp.JsonCreation_jsp._jspService(JsonCreation_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.
javax.servlet.ServletException:java.lang.NoClassDefFoundError:net/sf/ezmorph/Morphe r 這是什麼課程?它是一種依賴性嗎?看起來像Java找不到它。 –
實際上錯誤顯示在第36行jasonarrayobject.put的定義未被檢測到 –
Nah,我敢肯定你的問題是它無法找到類net/sf/ezmorph/Morpher ... –