The use of the MAP interface. . . The problem encountered today. .

xiaoxiao2021-03-06  114

/ ** * Remove all parameter lists from the request, then save it to the database to the database * @Param Req httpservletRequest * / protected void DosaveParaters (httpservletRequest Req) {

Map pMap = req.getParameterMap (); system.out.println ("zqbtest ****** map:" pmap); item entries = pmap.keyset (). Iterator (); system.out.println "zqbtest ***** ipterator ::" entries); while (entries.hasnext ()) {map.entry entry = (map.entry) entries.next (); // This is wrong! ! ! String key = (string) entry.getKey (); string value = (string) entry.getValue (); mtst.insertsaveParameter (WorkItemid, key, value);}

}

Background printing information:

ZQbtest ******* map: {reason = [ljava.lang.string; @ 6e9cc3, fxcfh = [ljava.lang.string; @ 75d174, bsize = [ljava.lang.string; @ a4a32, readonlysendPersons = [ Ljava.lang.String; @ d539f, specialsendstep = [Ljava.lang.String; @ 6d0085, nextsteppersons = [Ljava.lang.String; @ 3d4817, fxfba = [Ljava.lang.String; @ 47e54e, specialsendpersons = [Ljava. Lang.String; @ 1f91ac, fxfaax = [ljava.lang.string; @ 14f467, unknown5copy = [ljava.lang.String; @ 39d072, unknown3 = [ljava.lang.string; @ 2422d9} zqbtest **** iTerator :: java.util.hashmap $hashiterator@6c12f3

Throw anomalies as follows: http status 500 -

-------------------------------------------------- ------------------------------

TYPE EXCEPTION Report

Message

Description The Server Encountered An Internal Error () That Prevented It from fulfecting

This Request.

EXCEPTION

Java.lang.classCastException: java.lang.string at com.neusoft.fd.processor.wfprocessor.dosaveParameters (wfProcessor.java: 1149) Program After modified code: / ** * Remove all parameter lists from the request, * and then save the work item id together database * @param req HttpServletRequest * / protected void doSaveParameters (HttpServletRequest req) {Map pMap = req.getParameterMap (); Iterator entries = pMap.entrySet () iterator ();. while (entries .hasnext ()) {

Map.Entry entry = (java.util.map.entry) entries.next (); string key = (String) entry.getKey (); string [] values ​​= (String []) entry.getValue (); for () Entry.getValue (); INT i = 0; i

} The reason is as follows: 1. Iterator entries = pmap.Eutrator (); to remove items; 2, entries.Next () is a map of java.util.Map.Entry is MAP Interior interface of the interface; its getValue method, returning is a string []; Note: The keyset in the map returns a set object that contains the Key value included in the map; VALUES in Map is a Value containing map A Collection object of the value; you can view the JDK's API document.

转载请注明原文地址:https://www.9cbs.com/read-100767.html

New Post(0)