我正在JSP中开发电影租赁应用程序。在复选框的帮助下选择电影后,当我使用它进行迭代时,它会给我空指针异常。 这是Statement.jsp文件的代码,它为租借的电影创建语句...
<%@page language="java" %>
<%@page import="java.sql.*, java.util.*, mrs.*" %>
<html>
<head>
<title>Movie Rental Application</title>
</head>
<body>
<%@include file="Connection.jsp" %>
<% if (session.getAttribute("Name") != null) {
String[] checkboxes = null;
String[] days = null;
checkboxes = request.getParameterValues("c1");
days = request.getParameterValues("t1");
int i = 0;
for (String title : checkboxes) {
String Name = session.getAttribute("Name").toString();
int code = 0;
ResultSet rs = stmt.executeQuery("select Type from Movies where Title = '" + title + "'");
String Type = rs.toString();
if (Type.equalsIgnoreCase("REGULAR")) {
code = 0;
}
if (Type.equalsIgnoreCase("NEW RELEASE")) {
code = 1;
}
if (Type.equalsIgnoreCase("CHILDREN")) {
code = 2;
}
mrs.Movie m = new mrs.Movie(title, code);
int day = Integer.parseInt(days[i]);
i++;
mrs.Rental r = new mrs.Rental(m, day);
mrs.Customer c = new mrs.Customer(Name);
c.addRental(r);
stmt.executeQuery("insert into rents values('" + day + "','" + Name + "','" + title + "')");
String result = c.statement();
out.println(result);
}
stmt.close();
con.close();
%>
<% }%>
</body>
</html>
这是例外......
答案 0 :(得分:0)
您没有检查是否选中了复选框。
public Dictionary<string, List<DummyClass>> FilterAndGroupBy(string type, string date, List<string> names)
{
// Get the collection
var collection = GetDummyCollection();
var filter = new BsonDocument
{
{"Date", date},
{"Type", type}
};
// Create the filter
filter.Add("Name", new BsonDocument
{
{"$in", new BsonArray(indexNames)}
});
// Create the group, this does not work.
var group = new BsonDocument
{
{"_id",
new BsonDocument {
{"Name", "$Name"},
{"Result", new BsonDocument("$push", new BsonArray()) }
}
}
};
// Query the group with the filter
var resultslambda = collection.Aggregate().Match(filter).Group(group).ToList();
return new Dictionary<string, List<DummyClass>>();
}
您可以参考link以查看复选框根据上述条件返回的值。