Javascript passes an array of arguments to the background with the same property

  • 2020-03-30 01:45:11
  • OfStack

When we pass parameters, we often encounter parameters that pass the same properties to the background. The best choice is to use arrays. When we send to the background, we just need to define and use the array normally in javascript and pass it to the background as a parameter:
 
var arry= new Array(); 

arry[0] = "102"; 

arry[1] = "103"; 

arry[2] = "104"; 

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

Receiving methods in the background:
[code]
The String 'arry = request. GetParmeter ("' arry ");

String [] par = 'arry. Split (", ");
[code]
At this point, your par becomes an array in Java. The value of arry is "102,103,104", which means that in the process of passing, the browser will automatically convert the javascript array parameters into a comma-separated string, we just need to fetch the string in the background and divide it into the corresponding array according to the comma.

In addition, I have seen some people using json on the Internet, which is not very pleasant. Also useful request. GetParmeterValues methods, the specific use is as follows:

Use the same parameter in the foreground and pass it by multiple assignments:

Url = "test. The JSP? 'arry = 102 &' arry = 103 & 'arry = 104"

Remove in the background:

The String 'arry [] = request. GetParmeterValues ("' arry ");

The value of arry is {102,103,104}

Specific way is chosen according to his habit!

Related articles: