JavaScript sends the same property to the background as an array parameter _jquery

Source: Internet
Author: User
Tags javascript array
When we transmit parameters, we often encounter parameters that send some of the same attributes to the background, and the best option is to use arrays. When we transfer to the background, we simply define and use the array in JavaScript and pass it as a parameter to the background:
Copy Code code as follows:

var arry= new Array ();

ARRY[0] = "102";

ARRY[1] = "103";

ARRY[2] = "104";

url = "test.jsp?arry=" +arry;

In the background to accept the method:
[Code]
String Arry = Request.getparmeter ("Arry");

string[] par = arry.split (",");
[Code]
The par then becomes an array in Java. Where the value of Arry is "102,103,104" that is, in the course of the transfer, the browser automatically converts the JavaScript array parameters into comma-delimited strings, and we only need to remove the string in the background and divide it into the corresponding array by commas.

In addition, I've seen the use of JSON on the internet, it doesn't feel good. Also useful request.getparmetervalues method, the specific use is as follows:

Use the same parameter in the foreground and assign the value more than once:

Url= "test.jsp?arry=102&arry=103&arry=104"

Out in the background:

String arry[] = request.getparmetervalues ("Arry");

The value of the Arry at this time is {102,103,104}

The concrete way according to own custom choice!
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.