Implementation of JSP and servlet after page single deletion and multiple deleted page jumps

Source: Internet
Author: User

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

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.