Usually we use Request.getparameter (parameter name) to get the arguments above or Ajax.data submitted by the URL, but for example, using the Httppost.setentry in HttpClient () The method submits the parameter is not the parameter name, uses the Request.getparameter (parameter name) cannot obtain the parameter value, we may use the Request.getinputstream () (Io flow) method to obtain the content in the body, Gets a JSON string, then uses the Jsonobject.fromobject (JSON string), and resolves to the values of each parameter in it.
Suppose we get the content of both URL-submitted parameters, there are httpclient in the Httppost.setentry () of the method submitted parameters, this time how to get the value of the parameter?
The normal idea should be: First use Request.getparameter (parameter name) to get the parameters above the URL,
Then use Request.getinputstream () (IO stream) to get the contents of the body without parameter names
The parameter contents obtained using IO Stream are found to be null
The reason: servlet specification: The data in the request body is populated in the parameter collection when the following conditions are met
1: is a HTTP/HTTPS request
2: The request method is post
3: Request type (Content-type) is application/x-www-form-urlencoded
4:servlet called the GetParameter series method
If the above conditions are not met at the same time, the associated form data is not set in the parameter collection of the request.
The relevant data can be accessed through Request.getinputstream (). Conversely, if the above conditions are met,
The related form data will no longer be read by Request.getinputstream ().
According to the description of this specification, when we call the Request.getparameter (parameter name) method,
The data (the request body) submitted through the Httppost.setentry () in HttpClient is populated into the parameter collection.
So the subsequent fetch of the data stream through the Request.getinputstream is empty.
The final solution to this problem is to put the Request.getparameter (parameter name);
After Request.getinputstream, this avoids the servlet specification, and can get the desired parameter values normally.