- Java code
//这个是根据ID查询出来的一个Namepublic ActionForward getNameBySID(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); String deptName = ""; String deptLevel = request.getParameter("deptLevel"); //String deptLevel ="0001"; try { deptName = deptService.GetDeptNameByDeptLevel(deptLevel); } catch (BusinessServiceException e) { e.printStackTrace(); } System.out.println(deptName+"&&&&&&&"+deptLevel); JSONObject json = new JSONObject(); json.put("json", deptName); return null; }
- JScript code
function onNodeSelect(sID){ alert(sID); if(sID.indexOf("000")==0){ $.ajax({ type:"post", url:"${pageContext.request.contextPath}/measureWorkflow.do", cache:false, dataType:"json", data:"method=getNameBySID&deptLevel="+sID, success:function(data){ alert(${deptName}); window.frames["process"].document.write ('<input type="text" value="aa"><br>'); } });} }
------解决方案--------------------------------------------------------
要是json不能这样写
- Java code
JSONObject json = new JSONObject(); json.put("json", deptName);return json;
------解决方案--------------------------------------------------------
呵呵,你的问题缺一个关键的东东:
response.setCharacterEncoding("utf-8");//编码
response.getWriter().print(json.toString());//输出
------解决方案--------------------------------------------------------
- Java code
response.getWriter().print(json.toString());//输出
------解决方案--------------------------------------------------------
后台品字符串成为JSON格式 然后使用AJAX返回到页面。