Source of Request Parameters
1. query string of the request URL, such as/localhost/abc/test? Abc = ddd & bbb = ccc, the string following the question mark
2. For a POST request, if Content-Type = "application/x-www-form-urlencoded", the parameter comes from the request Content (in the same format as the query string)
For the first case, the request parameters can be read in any case using the getParameter series method using ISO-8859-1 Encoding
In the second case, it is a bit complicated. It involves the following methods of ServletRequest:
GetParameter Generation Method
GetCharacterEncoding
GetInputStream
GetReader
GetCharacterEncoding
Generally, the request characterEncoding comes from the charset parameter of Content-Type. If the charset parameter is not set, it is null.
GetInputStream and getReader (correct the error in Note 1)
These two methods are used to read the request content and cannot be used at the same time. If one method is used and another method is attempted, IllegalStateException is thrown.
The getReader method returns the BufferedReader object that uses getCharacterEncoding to encode the string. If it is null, The ISO-8859-1 is used.
GetParameter Generation Method
When the parameter comes from the request content, because the stream is used to read the request content
1. If the getInputStream and getReader methods are used before using the getParameter series methods, the request parameters cannot be obtained using the getParameter series methods.
2. When the getParameter series method is used before the stream is used, the stream should have reached the end, and the request parameters can be obtained.
3. Use getCharacterEncoding to encode the parameter. If it is null, use the ISO-8859-1
4. The getInputStream or getReader method is not directly used to obtain the stream for parsing parameters, because this will affect the status and cause the getInputStream or getReader method to throw IllegalStateException