给你发个jQuery解析xml的吧。jQuery.ajax({ type: "POST", url: url, datatype: "xml", data: {"action":"BayassetChangePagebean.getUserOrCoordinatorAjax","assetsNum":assetsNum}, beforeSend :function(xhr){ xhr.setRequestHeader("Ajax-Request", "true"); }, success: function(xml){ jQuery(xml).find("user").each(function(){ var userName = jQuery(this).attr("userName"); var userId = jQuery(this).attr("userId"); var userType = jQuery(this).attr("userType"); if(userType=='coordinator'){ jQuery("#coordinatorTD").append(userName+" "); }else{ document.getElementById('currentUserTD').innerText=userName } }); },complete : function(){ document.getElementById("form1:outgoingUserName").value=document.getElementById('currentUserTD').innerText } });后台记得设置下 setContentType("text/xml"); 返回的时xml格式的字符串就可以了。
你想获取list应该是有很多值要处理对吧!推荐你使用ajax + json我这边有个struts2 + ajax + json的例子,你看一下或许会对你有帮助http://hi.baidu.com/zhaotao_king/blog/item/464d167fddc2ba250cd7daa4.html有问题可百度Hi我,good luck!~
有一个第三方类库可以提供吧对象封装成JSON对象,我用的就是这个。import net.sf.json.JSONArray;import net.sf.json.JSONObject;这个你自己去网上下载吧。public void list(HttpServletRequest request, HttpServletResponse response,PrintWriter pw){ PartsDao dao = new PartsDao(); List<Parts> partsList = dao.getList(); JSONObject items = new JSONObject(); JSONArray result = null; try { result = new JSONArray(); for (int i = 0; i < partsList.size(); i++) { Parts parts = (Parts)partsList.get(i); JSONObject jsonParts = new JSONObject(); jsonParts.put("ID", parts.getPartsId()); jsonParts.put("name", parts.getName()); jsonParts.put("PP", parts.getBrand()); jsonParts.put("LGBH", parts.getLGBH()); jsonParts.put("TH", parts.getTH()); jsonParts.put("YCBH", parts.getYCBH()); jsonParts.put("DW", parts.getFormat()); jsonParts.put("GG", parts.getAttribute()); jsonParts.put("BZ", parts.getRemark()); jsonParts.put("status", parts.getStatus() == 1 ? "1" : "0"); result.add(jsonParts); } } catch(Exception ex) { ex.printStackTrace(); } items.put("identifier", "ID"); items.put("label", "name"); items.put("items", result); items.write(pw); }