我需要你的帮助。
我使用 AJAX 将这个数组从 Javascript 传递到 Java Servlet。
Javascript 和 AJAX 片段代码:
var BuildingNo = [];
$(xml).find('BUILDING').each(function(){
BuildingNo.push($.trim(this).children('BuildingNo').text());
}
传递给 Java Servlet 之前的 BuildingNo 值。
alert(BuildingNo);
// 00101,00102,00103,00104,00105
当我通过 Ajax 将 BuildingNo 传递给 Java Servlet 时 JSON.stringify(BuildingNo) 的值。
data: { BuildingNo : JSON.stringify(BuildingNo) },
alert(JSON.stringify(BuildingNo));
// ["00101","00102","00103","00104","00105"]
这是我用来将 BuildingNo 传递给 oldBuilding 列表的 Java Servlet 片段代码。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws (ServletException, IOException {
List <String> oldBuildingList = Arrays.asList(request.getParameter("BuildingNo");
logger.info(oldBuildingList);
// [["00101","00102","00103","00104","00105"]] -- This is a wrong format.
//I have a Java code here which captures a new list of BuildingNo from another service.
List <String> newBuildingList = new ArrayList <String>();
logger.info(newBuildingList.toString());
// [00106,00107,00108,00109,00110] -- This should be the correct format of oldBuildingList.
}
如何使用 oldBuildingList 获得相同格式的 newBuildingList?
心有法竹
相关分类