问题描述:

I have a ModelMap variable "model", the value object contained in the model map itself is a HashMap.

Controller code:

public String func(ModelMap model)

{

HashMap<String, List<String> aMap = new HashMap<String, List<String>();

ArrayList<String> aList = new ArrayList<String>();

....// give aList some data

aMap.put("keystring", aList);

model.addAttribute("aMap", aMap);

String view = "test";

return view;

}

test.jsp code:

 var data = '${aMap}';

// I know this gets the entire aMap including its key ("keystring")

// and the value (aList)

var key ='${aMap}.key';

alert(key);

var value ='${aMap}.value';

alert(value);

I also tried:

 var va= data.key; // also tried data[key], data['key']

alert(va);

but they all printed either an empty string or undefined. However, if I printed "data", then I can see the entire map.

How do I access aMap's key ("keyString") and the value (aList) from test.jsp script part ? Any help will be appreciated.

网友答案:

You might want to take a look at this solution How to iterate HashMap using JSTL forEach loop?

It also seems that in your method should not be @ResponseBody since you are returning a view name.

相关阅读:
Top