gpt4 book ai didi

java - 取消 JAVA JSP 上的预订

转载 作者:行者123 更新时间:2023-11-29 17:20:49 25 4
gpt4 key购买 nike

我有一个简单的 Web 应用程序,可以在其中预订房间。如果我继续预订的房间,我会收到我已预订的房间的列表。现在我想实现一个简单的按钮来删除特定的预订。在我的数据库中,我有:

hotel_booking

使用此参数:

cid, cname, email, arrival_date, departure_date, person, room, type_room,comment, status, uid.

现在我已经创建了:

cancel.jsp

这是代码:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import ="java.sql.*" %>
<%
int id;
int person;
int room;



id = Integer.parseInt(request.getParameter("id"));
// out.println(id);
String cname = request.getParameter("cname");
// out.println(cname);
String email = request.getParameter("email");
String arrival = request.getParameter("arrival_date");
String departure = request.getParameter("departure_date");
person = Integer.parseInt(request.getParameter("person"));
room = Integer.parseInt(request.getParameter("room"));

String type_room = request.getParameter("type_room");

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/HotelReservation","root" ,"123456789");

String del = "delete from hotel_booking where id='" + Integer.parseInt(request.getParameter("id")) + "'AND cname='" + request.getParameter(cname) + "'AND emal='" + request.getParameter(email) + "'";

java.sql.Statement st = con.createStatement();

int rowNum = st.executeUpdate(del);
response.sendRedirect("home.jsp");
st.close();
%>

在 Booking.jsp 中,我插入了此表单作为取消按钮:

<form action='cancel.jsp'>
<input type='submit' name='cancel' value='Cancel Reservation'>
<input type="hidden" name="id" value=\""+id+"\">
</form>
</div>

但是我收到了这种错误:

HTTP Status 500 – Internal Server Error

Type Exception Report

Message An exception occurred processing [/cancel.jsp] at line [10]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: An exception occurred processing [/cancel.jsp] at line [10]

7:
8:
9:
10: id = Integer.parseInt(request.getParameter("id"));
11: // out.println(id);
12: String cname = request.getParameter("cname");
13: // out.println(cname);


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:593)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:482)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

java.lang.NumberFormatException: For input string: "\""+id+"\""
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:580)
java.lang.Integer.parseInt(Integer.java:615)
org.apache.jsp.cancel_jsp._jspService(cancel_jsp.java:128)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:444)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.

如何解决?每次有人预订房间时,我的数据库中的 cid 参数都会自动增加一。谢谢大家

最佳答案

尝试下面的代码

<form action='cancel.jsp'>
<input type="hidden" name="id" value="<%=id%>">
<input type='submit' name='cancel' value='Cancel Reservation'>
</form>
</div>

因为 id 的值作为“\”“+id+”\“”传递。但是在您的代码中,您尝试解析包含非数值的字符串,因为 Integer 抛出 NumberFormatException。

关于java - 取消 JAVA JSP 上的预订,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51268723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com