这是我的JSP代码,用于使用数据库获取用餐的结束时间并将其与系统时间进行比较。我使用了if语句来查看时间是否早于结束时间,然后重定向到另一页,但是如果时间超过用餐的结束时间,则会显示错误。
这很重要,if语句有效,但不像我刚才解释的那样。
有什么想法吗?预先感谢...
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<%
String meal = request.getParameter("meal");
Connection con = null;
Statement st = null;
ResultSet rs = null;
try{
con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/eoms?autoReconnect=true&useSSL=false","root","eoms");
st=con.createStatement();
String select="SELECT * FROM eoms.schedule;";
rs = st.executeQuery(select);
String mealName = null;
Time dueTime = null;
Time time = null;
int found = 0;
while(rs.next()){
mealName = rs.getString(1);
dueTime = rs.getTime(3);
java.util.Date d = new java.util.Date();
time = new Time(d.getTime());
if(meal.equalsIgnoreCase(mealName) && time.before(dueTime)){
session.setAttribute("mealName", mealName);
con.close();
found = 1;
response.sendRedirect("header.jsp");
}
else
continue;
}
if(found == 0){
session.setAttribute("orderror",meal+mealName+time+dueTime+ "The time for taking the order is over...");
con.close();
response.sendRedirect("placeOrder.jsp");
}
}
catch(Exception e){
out.println(e.getMessage());
}
%>
</body>
</html>
答案 0 :(得分:0)
如评论中的@Andreas所述,在Country max = countries[0];
之后添加public static Country maximum(Country[] countries) {
Arrays.sort(countries);
return countries[0];
}
并删除break
。
对于其他情况,我建议使用response.sendRedirect("header.jsp")
来获取实际时间,并使用此else continue;
将其转换为java.time.LocalTime
以此替换最后的Java代码
java.sql.Time