在Chromium上的Ubuntu 16.04LTS上运行带有tomcat8的JSP时出现此错误。
一切都在运行罚款,直到我修改了
sql = conn.prepareStatement(“SELECT TITLE,VENUE,DETAILS, MAXPERSONS,COSTPERPERSON,DURATION,CEP日期“);
和
<%= ceps.getString(“...”)%>线
匹配新的数据库架构。
我无法弄清楚出了什么问题。
你能帮忙解决这个问题吗?还有什么我需要改变整体吗?
JSP页面:view-cep.jsp
<!DOCTYPE html>
<html>
<head>
<title>View CEP</title>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%Class.forName("com.mysql.jdbc.Driver"); %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
</head>
<body class="content-wrapper">
<div class="content-page-heading">CEP - Further Action</div>
<%!
public class Cep {
String URL = "jdbc:mysql://localhost:3306/DBName";
String USERNAME = "username";
String PASSWORD = "password";
Connection conn = null;
PreparedStatement sql = null;
ResultSet res = null;
public Cep () {
try{
conn = DriverManager.getConnection (URL, USERNAME, PASSWORD);
sql = conn.prepareStatement ("SELECT TITLE, VENUE, DETAILS, MAXPERSONS, COSTPERPERSON, DURATION, DATE FROM CEP");
}
catch (Exception e) {
System.out.println(e);
}
}
public ResultSet getCep () {
try {
res = sql.executeQuery();
}
catch (Exception e) {
System.out.println(e);
}
return res;
}
}
%>
<%
Cep cep = new Cep ();
ResultSet ceps = cep.getCep ();
while (ceps.next ()) { %>
<div class="content-row">
<div class="content-title content-dropDown-point">
<%= ceps.getString("TITLE") %>
</div>
<div class="content-details content-dropDown">
<hr>
<table>
<tr>
<td>Venue:</td>
<td><%= ceps.getString("VENUE") %></td>
</tr>
<tr>
<td>Details:</td>
<td><%= ceps.getString("DETAILS") %></td>
</tr>
<tr>
<td>Number of Employees Accepting:</td>
<td><%= ceps.getString("MAXPERSONS") %></td>
</tr>
<tr>
<td>Cost per Employee:</td>
<td><%= ceps.getString("COSTPERPERSON") %></td>
</tr>
<tr>
<td>Duration:</td>
<td><%= ceps.getString("DURATION") %></td>
</tr>
<tr>
<td>Date of Commencement:</td>
<td><%= ceps.getString("DATE") %></td>
</tr>
<tr>
<td><button>Submit</button></td>
</tr>
</table>
</div>
</div>
<% } %>
</body>
</html>
错误:在第58行处理JSP页面/forms/view-cep.jsp时发生异常
org.apache.jasper.JasperException: An exception occurred processing JSP page /forms/view-cep.jsp at line 58
55: Cep cep = new Cep ();
56: ResultSet ceps = cep.getCep ();
57:
58: while (ceps.next ()) { %>
59: <div class="content-row">
60: <div class="content-title content-dropDown-point">
61: <%= ceps.getString("TITLE") %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:578)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
org.apache.jsp.forms.view_002dcep_jsp._jspService(view_002dcep_jsp.java:174)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
MYSQL数据库架构:
+---------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| TITLE | varchar(30) | NO | | NULL | |
| VENUE | varchar(30) | NO | | NULL | |
| DETAILS | varchar(30) | NO | | NULL | |
| MAXPERSONS | varchar(30) | NO | | NULL | |
| COSTPERPERSON | varchar(30) | NO | | NULL | |
| DURATION | varchar(30) | NO | | NULL | |
| DATESTART | varchar(30) | NO | | NULL | |
+---------------+---------------+------+-----+---------+-------+
答案 0 :(得分:0)
根据您发布的架构,您的表中没有名为DATE
的列,如下所示。同样,DATE
是一个保留词,即使你想使用它,你也应该正确地逃避它。
SELECT TITLE, VENUE, DETAILS, MAXPERSONS, COSTPERPERSON, DURATION, DATE <--thsi one
FROM CEP
可能您的意思是使用DATESTART
列
SELECT TITLE, VENUE, DETAILS, MAXPERSONS, COSTPERPERSON, DURATION, DATESTART FROM CEP