SERVLET-API API documentation GET request parameters

Source: Internet
Author: User

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

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.