Read the Code study Java:request.getParameterNames

Source: Internet
Author: User

1 protectedMap<string, string>Initrequestparams (HttpServletRequest request) {2map<string, string> parammap =NewHashmap<string, string>();3         if(Request = =NULL) {4             returnParammap;5         }6Enumeration<?> Paramnames =request.getparameternames ();7 /*8 The enumeration<?> delegate can pass any type, which is the wildcard character, the subclass of object and all the objects in Java. 9 Ten The Request.getparameternames () method is to fetch (including button) all form objects that have the name attribute in the form form on the sending Request page. Returns an enumeration of type enumeration. One  A traverse by Enumeration's hasMoreElements () method. The value of the enumeration is then obtained by the Nextelement () method. The value at this time is the value of the Name property of all controls in the form form. -  - Finally, the value of the form control is obtained by using the Request.getparameter () method. the */ -         if(Request! =NULL&& Paramnames! =NULL&&paramnames.hasmoreelements ()) { -              while(Paramnames.hasmoreelements ()) { -String paramname =(String) paramnames.nextelement (); +string[] Paramvalues =request.getparametervalues (paramname); - /* + first get the variable mane and then get its value, for Getparametername () whose value is the name of the variable/object, Getparametervalue () Gets the value of the variable/object.  A The request.getparametervalues ("name") method gets the value of the Name property in all form forms. The method returns an array. Iterating through an array will give you a value. at */ -                 if(Paramvalues.length = = 1) { -Parammap.put (ParamName, paramvalues[0]); -}Else { - parammap.put (paramname, arrayutils.tostring (paramvalues)); -                 } in             } -         } to         returnParammap; + } - /* the the value of Request.getparameternames () is unordered request.getparametervalues () is arranged in the order of the controls in the From form. * */

Read the Code study Java:request.getParameterNames

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.