Realization and doubt of JS asynchronous transitive array action acceptance

Source: Internet
Author: User
Tags array object string

Recent development encountered a page pass array to the action background list type, the Received list object is not imagined according to the array element position corresponding to the acceptance, such as the array of 0 bits inserted into the list object 0 position,

Instead, the entire contents of the array are inserted into the first position of the list collection. After repeated experiments, did not find a good solution, can only be the rough way to record the implementation, in order to make a point of hope that we can give a better way to achieve.

This is the JSP page code: Asynchronously submitting an array to the action:

   insert title here                      Test 
         test
         test
         test
        test
               

  Background Java code: An array of accepted page passes that is inserted into the first position of the list collection after a test array.

@Controller @Scope ("prototype") public class Loginaction extends Actionsupport {    private List Ajaxfield = new ArrayList ();     public void Testarray () {        string str = (string)
Ajaxfield.get (0);
        System.out.println (str);
        list List = new arraylist ();
        string[] STRs = Str.split (",");         for (String string:strs) {       
     System.out.println (string);
            List.add (string);        }         for (int i = 0; i < Ajaxfield.size (); i++) {            System.out.println(Ajaxfield.get (i));        }           
HttpServletResponse response = Servletactioncontext.getresponse ();         try {          
  PrintWriter write = Response.getwriter ();
            Response.setcontenttype ("text/html");                      Write.print ("Hello");                       Write.flush ();                       write.close ();          } catch (IOException e) {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;  E.printstacktrace ();        }    }

Although the process of implementing array delivery is somewhat flawed, it is still true for asynchronous Ajax delivery, but it is also useful to pass the variable only if the array is not passed.



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.