Spring MVC fail to pass large data in JSONArray from controller to JSP page -
i have list of department names needed passed controller view. following code works fine if there few department names passed, ex. 3 names. doesn't work when number of departments becomes large, example, 300 names, first alert in jsp code doesn't invoked in case. printed length of jsonarray depnamejsonlist controller, shows correct number of names. reason used json because need use in jquery datatable. why can't passed view if there 300 names? many thanks!
controller:
@requestmapping(value = "/getdepartment", method = { requestmethod.post, requestmethod.get }) public modelandview getdepartment() { modelandview mv = new modelandview(); jsonarray depnamejsonlist= new jsonarray(departmentnames); logger.debug("depnamejsonlist size: " + depnamejsonlist.length()); // printed 309 mv.addobject("depnamejsonlist", depnamejsonlist); mv.setviewname("displaydepartment"); return mv; }
jsp:
$(document).ready(function() { alert("document ready"); var deplist = $.parsejson('${depnamejsonlist}'); alert(deplist); });
i guessyou have special characters in json string. in situations one, must careful in special characters 'or " or \r or \n or \t; 1 (or more of thiese characters in json string throw error in json.parse method. can suggest use org.springframework.web.util.htmlutils class in order encode special characters in html entities
Comments
Post a Comment