samedi 21 mars 2015

Printing an array of String sent from Spring MVC Controller shows only "toJSON" in javascript

I have a list of String (department names) passed from a controller to a JSP page. I need to get each individual name and use it as the key to a map (the map value will be a list of employees for that department). However, when I do alert for each department name, I got a string "toJSON". How do I get each name in a readable string? Some department name contain special character like apostrophes, slash. Many Thanks!


Controller:



@RequestMapping(value = "/getDepartment", method = { RequestMethod.POST, RequestMethod.GET })
public ModelAndView getDepartment()
{
ModelAndView mv = new ModelAndView();
mv.addObject("depNameList", depNameList); // depNameList is a type of List<String>
mv.setViewName("displayDepartment");
return mv;
}


JSP:



$(document).ready(function()
{
var depArr = "${depNameList}";
alert(depArr); // this printed a list of department names
for ( var i in depArr)
{
alert("i=" + i); // this printed "i=toJSON"
alert("i=" + JSON.stringfy(i)); // this didn't get invoked.
}
});

Aucun commentaire:

Enregistrer un commentaire