JSP page to implement check box selection and __js, check delete function

Source: Internet
Author: User

form page in JSP

<span style= "FONT-SIZE:12PX;" ><form action= "<%= request.getcontextpath ()%>/delectservlet" Method=post> <tr> <th&gt
	  				  	;
	  				  	  	   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&gt
  	  		;${person.habit}</td> <td>${person.salary}</td> <td>${person.other}</td> <td>${person.role}</td> </tr> </c:forEach> &LT;/FORM&GT;&LT;/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 ();
    }


Related Article

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.