我有一个调用 MySQL 数据库的服务器。
deletePage
方法看起来是这样:
public void deletePage(PageData delete) {
String firstQuery ="Delete FROM pages Where ID= "+delete.getId()+" ;";
try {
statement = connection.createStatement();
statement.executeUpdate(firstQuery);
System.out.println("Expense is deleting");
} catch (SQLException e) {
System.out.println("Expense isn t deleting - SQLException");
e.printStackTrace();
}
}
delete.jsp
如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Add pages</title>
</head>
<body>
<form action="adminController">
<p>
<input type="hidden" name="operation" value="deletepage" />
<input type="hidden" name="parentid" value="<%= request.getParameter("id") %>" />
Enter ID of page you want to delete:<input name="id"><br>
<input type="submit" />
</p>
</form>
</body>
</html>
manadmin.jsp
:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%= request.getAttribute("menu") %>
</body>
</html>
if you run this code you ll see that my delete buttons stands after each page name. what i want to do is by pressing the delete button near the page to delete this page, there should be something like "are you sure you want to delete?", submit button"delete". but what i have managed to do looks like this(as in my code): whenever delete button is pressed, you have to enter id of page you want to delete, so no matter what delete button i press, it requests for id. but i just want to delete it right away. can anyone help?