1. If there is a GET request followed by the following parameters:
A=b&a2=b2&a3=b3&a4=b4.
If you want to get all the key,value. This time can be obtained according to the request getquerystring. However, there is a problem, and the GetQueryString method does not decode the parameters.
You can use the: String decode = urldecoder.decode (URL, "Utf-8") method to decode the operation.
2, if the request parameter is in the body, the GetQueryString method can not get the request parameters.
Can only be obtained by streaming through the getInputStream method. Here's how. Ioutils Use the Common-codes jar package, or you can directly implement the InputStream into a string
HttpServletRequest request = Getrequest (); Request.setcharacterencoding ("UTF-8"); InputStream is = Request.getinputstream (); byte[] Dataorigin = new byte[request.getcontentlength ()]; Ioutils.readfully (is, dataorigin); String result= new String (Dataorigin);
3, if there are many parameters, you can use the following methods to get all the request parameters and turn into a map
map<string, string> data = Maps.newhashmap ();
HttpServletRequest request = This.getrequest (); enumeration<string> names = Request.getparameternames (); while (Names.hasmoreelements ()) {String key = Names.nextelement (); String value = Request.getparameter (key); Data.put (key, value); }
SERVLET-API API documentation GET request parameters