Inacio Inacio - 1 year ago 61
JSON Question

JSON getParameter returns null while ${} does not

I am writing a simple webserver for my unity game. The problem is if I do

, it displays the JSON string but if I do it in scriptlet it returns null value.

@RequestMapping(value = "/")
public ModelAndView distance(CommandMap commandMap) throws Exception {
ModelAndView mv = new ModelAndView("distanceProc");
List<Map<String, Object>> list = sampleService.distance(commandMap.getMap());

JSONObject obj = new JSONObject();

for(int i = 0; i < list.size(); i++) {
obj.put("city", list.get(i));

String jsonString = obj.toString();

mv.addObject("list", jsonString);

return mv;






String data = request.getParameter("list");
System.out.println("Received Data: " + data);

returns null. Am I missing something?

Answer Source

Are you sure that list is http request parameter?

What will the result be on

String data = request.getAttribute("list");
System.out.println("Received Data: " + data);

EL expression ${list} will give you the value of list attribute in one of the page, request, session, and application scopes. If list is really http request parameter and you would like to access it via EL than use ${param.list}.

In case it solved the problem: