First, the PO on a self-written conversion class.
1 /**2 * @authorXfiler3 * @described Tool method for converting Request.getparametermap () to normal map4 * @paramRequest5 * @return6 */7 PublicMap<string, string>Convertmap (HttpServletRequest request) {8map<string, string> returnmap =NewHashmap<>();9 //Convert to EntryTenset<map.entry<string, string[]>> entries =Request.getparametermap (). EntrySet (); One //Traverse A for(Map.entry<string, string[]>entry:entries) { -String key =Entry.getkey (); -StringBuffer value =NewStringBuffer (""); theString[] val =Entry.getvalue (); - if(NULL! = Val && val.length > 0) { - for(String v:val) { - Value.append (v); + } - } + returnmap.put (Key, value.tostring ()); A } at - returnReturnmap; -}
And then we're going to ask why did we do it?
Let's put an error message:
java.lang.ClassCastException: [Ljava.lang.String; cannot is cast to java.lang.String at Com.xfiler.servlet.MyServlet.doGet (Myservlet.java:+)
This error message indicates that the map returned by Request.getparametermap () is not our usual map<object,object> type, but Map<string,string[]> You need to convert the value part.
So back to the beginning of the code can be seen, did this part of the conversion.
About type conversions and data acquisition for REQUEST.GETPARAMETERMAP ()