form page in JSP
<span style= "FONT-SIZE:12PX;" ><form action= "<%= request.getcontextpath ()%>/delectservlet" Method=post> <tr> <th>
;
Select/Reverse <input type= "checkbox" id= "Checkall" name= "Checkall" onclick= "Checkall (checkall)"/><br> <input type= "Submit" value= "Delete onclick=" return confirm (' OK delete selection. ' "align=" left "> <input type=" button "value=" Modify "onclick=" Dodelete () "align=" left "> </ th> <th> number </th> <th> username </th> <th> password </th> <th> name &L t;/th> <th> mailbox </th> <th> sex </th> <th> birthday </th> <th> Hobby
</th> <th> Salary </th> <th> other </th> <th> role </th> </tr> <c:foreach var= "Person" items= "${jsp}" > <tr> <td align = "center" ><input type= checkbox "Id= ' ${person.id} ' name= ' info 'Value= ' ${person.id} '/></td> <td>${person.id}</td> <td>${person.username}</td > <td>${person.passwd}</td> <td>${person.realname}</td> <td>${person .email}</td> <td>${person.sex}</td> <td>${person.birth}</td> <td>
;${person.habit}</td> <td>${person.salary}</td> <td>${person.other}</td> <td>${person.role}</td> </tr> </c:forEach> </FORM></SPAN&G T
JS Implementation of the full selection of the reverse function
<script type= "Text/javascript" >
function Checkall (checkall) {
arr = document.getelementsbyname (' info ' );
if (checkall.checked = = True) {for
(i=0;i<arr.length;i++) {
arr[i].checked = true;
}
} else{for
(i=0;i<arr.length;i++) {
if (Arr[i]). Checked==false) {
arr[i].checked = true;
} else
{arr[i].checked = false;
}}} </script>
Implementing the selected Servlet class for deletion
Package servlet;
Import java.io.IOException;
Import Java.io.PrintWriter;
Import Javax.servlet.RequestDispatcher;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Dao.dao;
Import Dao.daojdbcimpl; /** * Servlet Implementation Class Delectservlet */public class Delectservlet extends HttpServlet {private static fin
Al long serialversionuid = 1L; protected void ProcessRequest (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOE
xception {response.setcontenttype ("text/html;charset=utf-8");
PrintWriter Out=response.getwriter ();
string[] Selectdelete = request.getparametervalues ("info");
String ids = "";
for (int i=0;i<selectdelete.length;i++) {ids = = "" +selectdelete[i]+ "";
if (i!=selectdelete.length-1) ids+= ",";
try {dao DAO = new Daojdbcimpl ();
Dao.remove (IDS);Out.print (' <script language= ' JavaScript ' >alert (' delete succeeded.
'); window.location.href= ' Showservlet ';</script> ');
Out.flush ();
Out.close (); catch (Exception e) {//TODO auto-generated Catch Block}}/** * @see httpservlet#doget (httpservletre Quest request, HttpServletResponse response) * * protected void doget (HttpServletRequest request, HttpServletResponse
Response) throws Servletexception, IOException {processrequest (request, response); /** * @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response) * * protected void Dopo St (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {processreque
St (request, Response);
}
}
JDBC Database Delete data
Remove person public
void remove (String id) throws exception{
DBC = new Daojdbcimpl ();
String sql= "Delete from person where id" ("+id+");
PreparedStatement PST = Dbc.getconnection (). preparestatement (SQL);
Pst.executeupdate ();
Pst.close ();
Dbc.close ();
}