Batch delete in jsp

Source: Internet
Author: User

Submission page:

<% @ Page language = "java" import = "java. util. *, java. SQL. *, com. it. bean. *" pageEncoding = "UTF-8" %>
<Jsp: useBean id = "common" class = "com. it. bean. pageinfo" scope = "page"/>


<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> </title>
<Script language = "javascript" type = "text/javascript">
Var flag = 1;
Function selectAll (){
If (flag = 1 ){
If (common_delete.selectdelete.length! = Undefined ){
For (var I = 0; I <common_delete.selectdelete.length; I ++)
Common_delete.selectdelete [I]. checked = true;
} Else {
Common_delete.selectdelete.checked = true;
}
Flag = 0;
} Else {
If (common_delete.selectdelete.length! = Undefined ){
For (var I = 0; I <common_delete.selectdelete.length; I ++)
Common_delete.chxSong [I]. checked = false;
} Else {
Common_delete.selectdelete.checked = false;
}
Flag = 1;
}
}
</Script>
</Head>
<Body>
<Div align = "center">
<Div align = "center">
<Form name = "common_delete" method = "post" action = "../CommonDeleteServlet">
<Table bgcolor = "# FFFFFF" border = "0" cellspacing = "0" cellpadding = "5">
<Tr bgcolor = "# cc99cc">
<Td width = "10%" align = "center"> <input type = "button" name = "selall" value = "select all/invert" onClick = "selectAll (); "> </td>
<Td width = "10%" align = "center"> <font face = "文" size = "4"> NO. </font> </td>
<Td width = "10%" align = "center"> <font face = "文" size = "4"> description </font> </td>
<Td width = "10%" align = "center"> <font face = "文" size = "4"> Category </font> </td>
<Td width = "20%" align = "center"> <font face = "文" size = "4"> diagnosis </font> </td>
<Td width = "10%" align = "center"> <font face = "文" size = "4"> Frequency </font> </td>
</Tr>
<%
Int I = 0;
String setcolor;
Try
{
ResultSet rst1 = common. getCommon ("100 ");
While (rst1.next ())
{
If (I % 2 = 0)
Setcolor = "# ffffff ";
Else
Setcolor = "# D9D9D9 ";
%>
<Tr bgcolor = <% = setcolor %>
<Td width = "10%" align = "center"> <input type = "checkbox" name = "selectdelete" value = "<% = rst1.getString (1 ). trim () %> "> </td>
<Td width = "10%" align = "center"> <font face = "_ GB2312" size = "3"> <% = rst1.getString (1 ). trim () %> </font> </td>
<Td width = "10%" align = "center"> <font face = "_ GB2312" size = "3"> <% = rst1.getString (3 ). trim () %> </font> </td>
<Td width = "10%" align = "center"> <font face = "_ GB2312" size = "3"> <% = rst1.getString (2 ). trim () %> </font> </td>
<Td width = "20%" align = "center"> <font face = "_ GB2312" size = "3"> <% = rst1.getString (4 ). trim () %> </font> </td>
<Td width = "10%" align = "center"> <font face = "_ GB2312" size = "3"> <% = rst1.getInt (6) %> </font> </td>
</Tr>
<%
I ++;
}
Rst1.close ();
}
Catch (Exception e ){}
%>
<Tr> <td colspan = "3"> & nbsp; </td>
<Td align = "center">
<Input type = "submit" value = "delete" onclick = "return confirm ('Are you sure you want to select? ') "> </Td> </tr>
</Table>
</Form>
</Div>
</Div>
</Body>
</Html>

 

Processing page:


Public class CommonDeleteServlet extends HttpServlet {


/**
*
*/
Private static final long serialVersionUID = 1L;


/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @ Param request the request send by the client to the server
* @ Param response the response send by the server to the client
* @ Throws ServletException if an error occurred
* @ Throws IOException if an error occurred
*/
Public void doGet (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, IOException {
Request. setCharacterEncoding ("UTF-8 ");
PrintWriter out = response. getWriter ();
String [] selectdelete = request. getParameterValues ("selectdelete ");
String ids = "";
For (int I = 0; I <selectdelete. length; I ++ ){
Ids + = "'" + selectdelete [I] + "'";
If (I! = Selectdelete. length-1) ids + = ",";
}
String SQL = "delete from COMMON where id in (" + ids + ")";
Connection con = null;
Statement dodel = null;
DBcon dbcon = new DBcon ();
Try
{
Con = dbcon. getConn ();
Dodel = con. createStatement ();
Dodel.exe cuteUpdate (SQL );

Con. close ();
}
Catch (Exception e)
{
E. printStackTrace ();
}
Out. print ("<script language = 'javascript '> alert ('Do Success'); window. location. href = 'delete. jsp '; </script> ");
Out. flush ();
Out. close ();

}


/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @ Param request the request send by the client to the server
* @ Param response the response send by the server to the client
* @ Throws ServletException if an error occurred
* @ Throws IOException if an error occurred
*/
Public void doPost (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, IOException {
DoGet (request, response );
}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.