Wangyanyixiang_branch
RichardWang 4 months ago
parent 2dfbc22e14
commit 2d268a2fe4

@ -44,11 +44,18 @@ public class ChatServlet extends HttpServlet {
.build();
HttpResponse<String> apiResponse = client.send(apiRequest, HttpResponse.BodyHandlers.ofString());
/*
if (apiResponse.statusCode() == 200) {
PrintWriter out = response.getWriter();
out.print(apiResponse.body());
out.flush();
*/
if (apiResponse.statusCode() == 200) {
String responseBody = apiResponse.body();
String formattedResponse = formatResponse(responseBody); // 格式化响应
PrintWriter out = response.getWriter();
out.print(formattedResponse);
out.flush();
} else {
LOGGER.log(Level.SEVERE, "API request failed with status code: " + apiResponse.statusCode());
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
@ -60,4 +67,15 @@ public class ChatServlet extends HttpServlet {
response.getWriter().write("{\"error\":\"·þÎñÆ÷´íÎó: " + e.getMessage() + "\"}");
}
}
}
// 格式化函数
private String formatResponse(String responseBody) {
// 假设responseBody是字符串形式的JSON您可能需要先解析它
// 这里简单示例对字符串进行替换和格式化
return responseBody
.replaceAll("\\*\\*(.*?)\\*\\*", "<strong>$1</strong>") // 加粗文本
.replaceAll("\\n", "<br>") // 替换换行符
.replaceAll("(\\d+\\. )", "<li>$1") // 列表项处理
.replaceAll("\\s+", " "); // 去除多余空白
}
}

@ -30,10 +30,7 @@ public class check_login_reg extends HttpServlet {
throws ServletException, IOException {
String log_name = req.getParameter("log_name");
String tel=req.getParameter("reg_name");
String id=req.getParameter("reg_p_id");
String name=req.getParameter("reg_p_name");
String sex=req.getParameter("reg_p_sex");
String work=req.getParameter("reg_p_work");
String log_pwd = req.getParameter("log_pwd");
String reg_name = req.getParameter("reg_name");
String reg_pwd1 = req.getParameter("reg_pwd1");
@ -46,7 +43,7 @@ public class check_login_reg extends HttpServlet {
}
else if(log_name==null&&log_pwd==null&&reg_name!=null&&reg_pwd1!=null&&reg_pwd2!=null&&reg_pwd1.equals(reg_pwd2)) {
//调用注册方法处理注册
go_reg(id,name,tel,sex,work,reg_pwd1, req, resp);
go_reg(name,tel,reg_pwd1, req, resp);
}
else {
@ -70,7 +67,7 @@ public class check_login_reg extends HttpServlet {
try {
if(res.next()) {
String p_pwd = res.getString(6);
String p_pwd = res.getString(3);
if(pwd.equals(p_pwd)) {
session.setAttribute("user_id", name);
@ -122,7 +119,7 @@ public class check_login_reg extends HttpServlet {
System.out.println("出错信息如下:"+e);
}
}
protected void go_reg(String id,String name, String tel,String sex,String work,String pwd1,HttpServletRequest req, HttpServletResponse resp) {
protected void go_reg(String name, String tel,String pwd1,HttpServletRequest req, HttpServletResponse resp) {
//System.out.println("注册方法被调用了");
resp.setContentType("text/html;charset=utf-8");
@ -136,7 +133,7 @@ public class check_login_reg extends HttpServlet {
out.println("该手机号已有注册账号");
resp.setHeader("refresh", "2;url=index/login_reg.jsp");
}else {
sql = "insert into p_inf (p_id,p_name,p_tel,p_sex,p_work,p_pwd) values('"+id+"','"+name+"','"+tel+"','"+sex+"','"+work+"','"+pwd1+"')";
sql = "insert into p_inf (p_name,p_tel,p_pwd) values('"+name+"','"+tel+"','"+pwd1+"')";
int in_res = conn.executeInsert(sql);
//System.out.println(in_res);
if(in_res==1) {

@ -38,9 +38,10 @@ public class search_fly extends HttpServlet {
String departureYear = req.getParameter("departureYear");
String departureMonth = req.getParameter("departureMonth");
String departureDay = req.getParameter("departureDay");
String date=req.getParameter("date");
String sql = null;
if (departure.isEmpty() && destination.isEmpty() && departureYear.isEmpty() && departureMonth.isEmpty() && departureDay.isEmpty()) {
/*
if (departure.isEmpty() || destination.isEmpty() || departureYear.isEmpty() || departureMonth.isEmpty() || departureDay.isEmpty()) {
// 濡傛灉鎵<E78189>鏈夊瓧娈甸兘涓虹┖锛岄噸瀹氬悜鍒板師椤甸潰
resp.sendRedirect(url);
} else {
@ -68,6 +69,15 @@ public class search_fly extends HttpServlet {
req.setAttribute("errorMsg", "鏃ユ湡鏍煎紡涓嶆纭紝璇疯緭鍏ユ暟瀛<E69A9F>");
}
}
*/
if (date == null || date.isEmpty()) {
// 如果日期为空则重定向到某个URL这里假设是url变量
resp.sendRedirect(url);
} else {
// 构建SQL查询语句
sql = "SELECT * FROM flight WHERE 1=1";
sql += " AND DATE(f_Date)='" + date + "'";
db_conn conn = new db_conn();
ArrayList<flight> flightlist = new ArrayList<flight>();
@ -90,6 +100,9 @@ public class search_fly extends HttpServlet {
flight_info.setF_wide(res.getString(12));
flightlist.add(flight_info);
}
req.setAttribute("date", date);
req.setAttribute("departure", departure);
req.setAttribute("destination", destination);
req.setAttribute("flightlist", flightlist);
} catch (SQLException e) {
System.out.println("閿欒淇℃伅锛<E4BC85>" + e);

@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Thu Oct 17 20:23:36 CST 2024
#Sat Oct 19 14:02:21 CST 2024
artifactId=air_ticket_book
groupId=air_ticket_book
m2e.projectLocation=C\:\\Users\\RichardWang\\Desktop\\ai_agent

Binary file not shown.
Loading…
Cancel
Save