实现页面跳转

RichardWang 1 month ago
parent 6eae35b320
commit de9c02a2ee

@ -13,7 +13,7 @@ public class db_conn {
//数据库初始化连接
public db_conn() {
String URL="jdbc:mysql://localhost:3307/fly_ticket?useSSL=false&useUnicode=true&characterEncoding=UTF8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"; //数据库名3306
String URL="jdbc:mysql://localhost:3306/fly_ticket?useSSL=false&useUnicode=true&characterEncoding=UTF8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"; //数据库名3306
String USER="root"; //数据库用户名
String PWD="123456"; //数据库密码
try{

@ -8,8 +8,35 @@ public class flight { //
private String f_s_t=null;//起飞时间
private String f_a_t=null;//到达时间
private String f_p=null;//票价
private String f_d=null;//出发日期
private String f_delay=null;//延误率
private String f_food=null;//餐食情况
private String f_wide=null;//座位宽度
public String getF_wide() {
return f_wide;
}
public void setF_wide(String f_wide) {
this.f_wide=f_wide;
}
public String getF_food() {
return f_food;
}
public void setF_food(String f_food) {
this.f_food=f_food;
}
public String getF_delay() {
return f_delay;
}
public void setF_delay(String f_delay) {
this.f_delay=f_delay;
}
public String getF_d() {
return f_d;
}
public void setF_d(String f_d) {
this.f_d=f_d;
}
public String getF_n() {
return f_n;
}

@ -41,7 +41,7 @@ public class search_fly extends HttpServlet {
String sql = null;
if (departure.isEmpty() && destination.isEmpty() && departureYear.isEmpty() && departureMonth.isEmpty() && departureDay.isEmpty()) {
// 如果所有字段都为空,重定向到原页面
// 濡傛灉鎵<EFBFBD>鏈夊瓧娈甸兘涓虹┖锛岄噸瀹氬悜鍒板師椤甸潰
resp.sendRedirect(url);
} else {
sql = "SELECT * FROM flight WHERE 1=1";
@ -53,7 +53,7 @@ public class search_fly extends HttpServlet {
sql += " AND f_a_p='" + destination + "'";
}
if (!departureYear.isEmpty() && !departureMonth.isEmpty() && !departureDay.isEmpty()) {
// 验证日期格式
// 楠岃瘉鏃ユ湡鏍煎紡
try {
int year = Integer.parseInt(departureYear);
int month = Integer.parseInt(departureMonth);
@ -62,10 +62,10 @@ public class search_fly extends HttpServlet {
String departureDate = String.format("%04d-%02d-%02d", year, month, day);
sql += " AND DATE(f_Date)='" + departureDate + "'";
} else {
req.setAttribute("errorMsg", "日期格式不正确,请输入有效的年、月、日");
req.setAttribute("errorMsg", "鏃ユ湡鏍煎紡涓嶆纭紝璇疯緭鍏ユ湁鏁堢殑骞淬<EFBFBD>佹湀銆佹棩");
}
} catch (NumberFormatException e) {
req.setAttribute("errorMsg", "日期格式不正确,请输入数字");
req.setAttribute("errorMsg", "鏃ユ湡鏍煎紡涓嶆纭紝璇疯緭鍏ユ暟瀛<EFBFBD>");
}
}
@ -84,11 +84,15 @@ public class search_fly extends HttpServlet {
flight_info.setF_s_t(res.getString(6));
flight_info.setF_a_t(res.getString(7));
flight_info.setF_p(res.getString(8));
flight_info.setF_d(res.getString(9));
flight_info.setF_delay(res.getString(10));
flight_info.setF_food(res.getString(11));
flight_info.setF_wide(res.getString(12));
flightlist.add(flight_info);
}
req.setAttribute("flightlist", flightlist);
} catch (SQLException e) {
System.out.println("错误信息:" + e);
System.out.println("閿欒淇℃伅锛<EFBFBD>" + e);
} finally {
conn.closeDB();
}

Loading…
Cancel
Save