Single Delete page jump
1. First open the JSP page and find the Delete
2, this time to change it to a servlet URL, and decide what data to pass to the background, such as I need to pass a data to be deleted ID
ID is not something to hide (and the background does not need too much attention), so the information is attached to the URL on it, (BasePath refers to the Web App root directory, in the JSP add the following code can be used
<%== request.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + path + " /"; %>
${XXXX} is an El expression. After completing the above steps, you can test the URL changes and HTTP messages under Chrome F12
3. Establish the corresponding servlet mappings in Web. Xml.
<servlet> <Servlet-name>Deleteoneservlet</Servlet-name> <Servlet-class>Com.imooc.servlet.DeleteOneServlet</Servlet-class> </servlet> <servlet-mapping> <Servlet-name>Deleteoneservlet</Servlet-name> <Url-pattern>/deleteoneservlet.action</Url-pattern> </servlet-mapping>
4, the servlet gets the parameter call corresponding service can:
// Set Encoding Req.setcharacterencoding ("UTF-8"); // Accept the value of the page String id = req.getparameter ("id"); New Maintainservice (); Maintainservice.deleteone (ID); // page Jump Req.getrequestdispatcher ("/list.action"). Forward (req, resp);
Finally, the page needs to be initialized again.
Multiple Delete page jumps
1, the corresponding page long like this
Click "Delete" to get multiple data after checking the data you want to delete.
2, similarly, in the page to find the corresponding deletion words,
Use this button to submit a form to a servlet that deletes multiple messages
This time you need to use JS (because this is a separate, dynamic behavior), as shown below
/*** jquery uses a very concise syntax to get HTML elements--$ (), which is a special function * ${} returns all methods of an object, such as $ (). CSS () and $ (). Height () is both getter and setter * JQuery AJAX (asynchronous JavaScript and XML) has good support, and it is a property of $: $. AJAX*//*** Call Background Bulk Delete method*/function Deletebatch (basepath) {if($ (' input[type=checkbox]:checked '). Size () > 0) { $(' #mainForm '). attr ("action", BasePath + "Deletebatchservlet.action"); $(' #mainForm '). Submit (); /*** highly toxic. Written ${' #mainForm '} debugged for a long time*/ } Else{alert ("Please select the Message to delete"); }}
Then include the. js in
3, also need to do the work is, with the selected ID as information, the way is to add the ID of the radio box
Modify a Label
Use the same method to test
4, finally in the servlet to connect data, service, re-initialize the page is ok (also edit the Web. xml
Implementation of JSP and servlet after page single deletion and multiple deleted page jumps