How Java obtains the Get and POST request URLs and parameter lists

Source: Internet
Author: User

One get URL:
Getrequesturl ()

Two get parameter list:

1.getQueryString ()

applies only to get, For example, the client sends Http://localhost/testServlet?a=b&c=d&e=f, the a=b&c=d&e=f is obtained by request.getquerystring ().


2.getParameter ()
Both get and post can be used
However, if the post request is based on the encoding of the <form> form submission data, determine whether it can be used.
Can be used when encoding is (application/x-www-form-urlencoded).
This encoding (application/x-www-form-urlencoded) is simple, but it does not seem to be enough to transmit large chunks of binary data.
For data that transmits chunks of binary numbers, the browser uses a different encoding ("Multipart/form-data"), and the following two methods are required.

3.getInputStream ()
4.getReader ()
The above two methods obtain the package body of the HTTP request packet, because the Get method request generally does not contain the package body. So the above two methods are generally used for POST request acquisition parameters.

It is important to note that:
The three methods of Request.getparameter (), Request.getinputstream (), Request.getreader () are conflicting because the stream can only be read once.
Like what:
When the form form content is enctype=application/x-www-form-urlencoded encoded, the parameters are first obtained by calling the Request.getparameter () method.
Re-calling Request.getinputstream () or Request.getreader () has no access to the contents of the stream,
Because the system may have read the data submitted in the form in the form of a stream, or vice versa, when calling Request.getparameter ().

When the form form content is enctype=multipart/form-data encoded, even if the first call to Request.getparameter () does not get the data,
So the call to the Request.getparameter () method does not conflict with Request.getinputstream () or Request.getreader ().
Even if the Request.getparameter () method has been called, the data in the form can be obtained by calling Request.getinputstream () or Request.getreader ().
Request.getinputstream () and Request.getreader () are not mixed in the same response, and if mixed use throws an exception.

"" "" "if there is anything wrong or not good enough to write, hope that the big can be put forward. Also, please leave a comment and study together. 《《《《《《《《《

How Java obtains the Get and POST request URLs and parameter lists

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.