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&¶mnames.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