It is easy to obtain the parameters submitted on the jsp page, but it can be used to convert the parameters and values in the request into a map. The following is a map structure formed by printing the obtained parameters and values: map (key, value []), that is, the key is a String type, and the value is a String type array.
For example:
The form request contains the multi-choice box checkbox or the parameter t1 = 1 & t1 = 2 & t2 = 3 in the request.
Map structure:
The code is as follows: |
Copy code |
Key = t1; value [0] = 1, value [1] = 2 Key = t2; value [0] = 3
|
If map. get ("t1 & Prime;), the result will be: Ljava. lang. string; value is only in the array format, which prevents the same parameter name.
Example
The code is as follows: |
Copy code |
/** * Obtain the parameter Map from the request and return a readable Map. * * @ Param request * @ Return */ @ SuppressWarnings ("unchecked ") Public static Map getParameterMap (HttpServletRequest request ){ // Parameter Map Map properties = request. getParameterMap (); // Return Value Map Map returnMap = new HashMap (); Iterator entries = properties. entrySet (). iterator (); Map. Entry entry; String name = ""; String value = ""; While (entries. hasNext ()){ Entry = (Map. Entry) entries. next (); Name = (String) entry. getKey (); Object valueObj = entry. getValue (); If (null = valueObj ){ Value = ""; } Else if (valueObj instanceof String []) { String [] values = (String []) valueObj; For (int I = 0; I <values. length; I ++ ){ Value = values [I] + ","; } Value = value. substring (0, value. length ()-1 ); } Else { Value = valueObj. toString (); } ReturnMap. put (name, value ); } Return returnMap; } |