Request.getparametermap () usage notes in Java
One
According to the Java Specification: Request.getparametermap () returns the value of a map type that records the mapping of request parameters and request parameter values from the front-end (such as JSP pages) submitted requests. There's something special about this return value--Read only. Not as normal map type data can be modified. This is because of the limitations that the server has made in order to achieve certain security specifications. such as Weblogic,tomcat,resin,jboss and other servers have implemented this specification.
If it is really necessary to make changes after this value is made, create a new map object, copy the return value to the new map object, and replace the return value with the new map object.
Map Readonlymap = Request.getparametermap ();
Map Writeablemap = new HashMap ();
Writeablemap.putall (READONLYMAP);
Writeablemap.remove () or put ()
... Use Writeablemap in subsequent program code
Two
The return value for Request.getparametermap () should be in map<string,string[]> form when using generics, because sometimes a component like a checkbox will have a name to deal with value. So the key value pair in the map is the implementation of <String-->String[]>.
For example, it is easy to get the parameters submitted by the JSP page on the server side, but by Request.getparametermap () you can turn the parameters and values in the request into a map.
The following are the resulting parameters and values are printed, the resulting map structure: map (key,value[]), namely: Key is string, value is a string array.
For example: The parameters in Request t1=1&t1=2&t2=3 the map structure:
key=t1;value[0]=1,value[1]=2
Key=t2;value[0]=3
If the direct use of Map.get ("T1"), the resulting will be: Ljava.lang.String; Value is only an array form, which prevents the parameter names from having the same situation.
Map map = Request.getparametermap ();
Java.util.Enumeration enum=this.getrequest (). Getparameternames ();
while (Enum.hasmoreelements ()) {
string paramname= (String) enum.nextelement ();
String[] values=request.getparametervalues (paramname);
for (int i=0;i<values.length;i++) {
System.out.println ("[+i+"] "+paramname+" "+values[i]);
}
}
Third, when the number of parameters are not fixed and the parameter name does not duplicate, the method of taking values:
Map map = new HashMap ();
Gets the name of the parameter for the enumeration type, and the name of the parameter, if repeated, can only get the first
Enumeration enum =this.getrequest (). Getparameternames ();
while (Enum.hasmoreelements ()) {
String paramname = (string) enum.nextelement ();
String paramvalue = This.getrequest (). GetParameter (paramname);
Map
map.put (paramname, paramvalue) corresponding to the formation of the key value;
}