The request.getparametervalues of AJAX parameter group

Source: Internet
Author: User

Web projects, typically interacting with the background, use AJAX for data submission

In the process of data submission, the data object is generally submitted. However, in the usual process, a series of data is used to pass in. such as bulk deletion.

We can do this by passing in an array.

There are several ways to do this:

1. Pass in an array of objects directly

var param = [];
Param.push ({"Name": "IDs", "Value": ID});

$.ajax ({
Type: "POST",
Async:true,//default True, Async
Data:param,
URL: "<%=request.getcontextpath ()%>/manageuser/delmanageuser.action",
Success:function (data) {

}})

2. Incoming objects

           param.push (ID2);

    Param.push (ID1);
$.ajax ({
Type: "POST",
Async:true,//default True, Async
data:{
Ids:param
},
URL: "<%=request.getcontextpath ()%>/manageuser/delmanageuser.action",
Success:function (data) {}

})

For the above value, the background Java is taken value. See the code below


@RequestMapping (value= "Delmanageuser")
@ResponseBody
Public String Delmanageuser (HttpServletRequest request) {

try {
string[] ids = Request.getparametervalues ("ids[]");
for (String id:ids) {

Todo

}

}catch (Exception e) {

}

}

With this value, you get the array.

Let's sort out the GetParameter and getparametervalues.

First, the simple contrast

Request.getparameter used more, relatively familiar

Request.getparametervalues (String name) is to obtain data such as the CheckBox class (with the same name but multiple values). Receive array variables , such as the CHECKOBX type
Request.getparameter (String name) is the data that obtains the corresponding name, and returns the first value if there is a duplicate name . Receive generic variables , such as the text type

Cases:

1. Three text labels with the same name

<input type= "text" name= "test" value= "1"/>
<input type= "text" name= "test" value= "2"/>
<input type= "text" name= "Test" value= "3"/>

Request.getparametervalues ("test")-----------------[1, 2, 3]

Request.getparameter ("Test")------------------1

${paramvalues.test}

${param.test}

2. checkbox

<input type= "checkbox" Name= "Habit" value= "read" > Reading

<input type= "checkbox" Name= "Habit" value= "movie" > Movies

<input type= "checkbox" Name= "Habit" value= "game" > Games

Request.getparametervalues ("Habit")

Ii. topics related to this------hidden objects

1. JSP hidden Objects (implicit object)

An implied object is an object that can be used directly when writing a JSP Web page without having to make any declarations. JSP2.0 defines nine hidden objects

Request Response PageContext Session application out CONIFG page exception

Here, just mention the request and response two objects

The Request object represents the content requested by the client, for example, we have obtained the user input from the request and implemented the Javax.servlet.http.HttpServletRequest interface

The response object represents the result of the response client.

Above we used the request of the two methods GetParameter and getparametervalues, in fact, request there are several other important methods, here are only a few ways to get the request parameters

String GetParameter (string name) gets the parameter value of name

String[] Getparametervalues (String name) gets the parameter value of all name

Enumeration Getparameternames () get all the parameter names

Map<string, string[]> Getparametermap () get a map of all parameters of request

//

Returns a java.util.Map of the parameters of this request. Request parameters is extra information sent with the request. For HTTP Servlets, parameters is contained in the query string or posted form data.

Returns:
An
immutable java.util.Map containing parameter names as keys and parameter values as MAP values. The keys in the parameter map is of type String. The values in the parameter map is of type String array.

//

Several other hidden objects, such as response, also have a very important identity, and have the opportunity to specialize and publicize their illustrious status.

2. El Hidden Objects

El namely Experssion Language, since JSP2.0 formally become one of the standard specification of JSP, support servlet2.4/jsp2.0 container also support El syntax accordingly.

A common form such as <c:out value= "${3 + 7 * 4}"/>

El's Hidden object has 11 PageContext pagescope requestscope sessionscope applicationscope

param paramvalues Header headervalues Cookie Initparam

where Param and paramvalues are the corresponding Servletrequest.getparameter (string name) and Servletrequest.getparametervalues (string name)

The request.getparametervalues of AJAX parameter group

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.