I want to delete a user from my system but it just show an alert message with 'OK' button on both success or fail message. I have 2 related .java file whereas User.java (that declare the userID) and UserManager.java (that connect the java with mysql database and to manipulate data such as method deleteAUserFromDB() that u can find also in the jsp file below).I have also 2 jsp file that related to that java file whereas the form page and the action file. Below is the code that i'd apply on my action file:
deleteUserAction.jsp:
<%@ page import="java.lang.*" %>
<jsp:useBean class="spkp.UserManager" id="userManager" />
<jsp:useBean class="spkp.User" id="userToDelete" />
<jsp:setProperty name="userToDelete" property="userID"/>
<%boolean success=userManager.deleteAUserFromDB(userToDelete);
if(success){%>
<script>
alert('Success to delete!!!');
window.location='deleteUser.jsp';
</script>
<%}else{%>
<script>
alert('Fail to delete!!!');
window.location='deleteUser.jsp';
</script>
<%}%>
before that, deleteUser.jsp is just a form page where it shows the list of userID (using arrays) and the 'Delete' button to each information shown and below is the code to send the information to the deleteUserAction.jsp:
deleteUser.jsp
<jsp:useBean class="spkp.UserManager" id="userManager" />
<%@page import="spkp.User"%>
<%@ page language="java" import="java.lang.*" import="java.sql.*" %>
<jsp:useBean class= "spkp.MySQLConnection" id= "view" />
<html>
<head>
</head>
<body>
<table width="80%" align="center" border="1" bordercolor="#000000">
<tr>
<td width="200" height="28">UserID</td>
<td width="100">Delete User</td>
</tr>
<%
User[] allUsers = userManager.getAllUsersFromDB();
if(allUsers!=null)
{
for(int i=1;i<allUsers.length;i++)
{
%>
<tr>
<td><%= allUsers[i].getUserID()%></td>
<td align="center"><input type="button" value="Delete" onclick="window.location='deleteUserAction.jsp?userID=<%= allUsers[i].getUserID()%>'"/>
</td>
</tr>
<% } } %>
</table>
</body>
</html>
I have found many Javascript code for Confirmation Dialog Box that can apply in JSP such as: link1 and link2
but they just show the box with no function whether we click yes/no but not for delete any of the user from my database that I choose. I do try my best search for solution in a few day for this but I'm really stuck.