转载自:http://blog.csdn.net/prostore/article/details/4205183受益匪浅

接下来将要写一个jsonList.JSP页面来将结果承现给用户

Html代码 

  1. <%@ page language="java" contentType="text/html;charset=UTF-8"%>  

  2. >  

  3. <html>  

  4.   <head>  

  5.     <title>json 返回列表处理title>  

  6.     <script language="javascript">  

  7.         var xmlHttp = false;   

  8.         try{   

  9.             xmlHttp = new ActiveXObject("msxml2.XMLHTTP");   

  10.         }catch(e1){   

  11.             try{   

  12.                 xmlHttp = new ActiveXObject("microsoft.XMLHTTP");   

  13.             }catch(e2){   

  14.                 try{   

  15.                     xmlHttp = new XMLHttpRequest();   

  16.                 }catch(e3){   

  17.                     xmlHttp = false;   

  18.                 }   

  19.             }   

  20.         }   

  21.         if(!xmlHttp){   

  22.             alert("create xmlHttpRequest fail");   

  23.         }   

  24.         function jsonListResult(){   

  25.             xmlHttp.onreadystatechange = function(){   

  26.                 if(xmlHttp.readyState == 4) {   

  27.                     var userList = eval('(' + xmlHttp.responseText + ')');   

  28.                     var user = eval(userList.JSONRESULT);   

  29.                     var result = "";   

  30.                     result += "<tr><td>userIdtd><td>userNametd><td>sextd>tr>";   

  31.                     for(var i=0;i<user.length;i++) {   

  32.                         result += "<tr>";   

  33.                         result += "<td>"+user[i].userId +"td>";   

  34.                         result += "<td>"+user[i].userName+"td>";   

  35.                         result += "<td>"+user[i].sex+"td>";   

  36.                         result += "tr>";   

  37.                     }   

  38.                     result += "table>";   

  39.                     document.getElementById('jsonDiv').innerHTML = result;   

  40.                 }   

  41.             }   

  42.             xmlHttp.open("POST","jsonlist.action",true);   

  43.             xmlHttp.send(null);   

  44.         }   

  45.     script>  

  46.   head>  

  47.   <body>  

  48.     <div id="jsonDiv">div>  

  49.     <input type="button" value="show list" onclick="jsonListResult();">  

  50.   body>  

  51. html>  

[html] view plaincopy

  1. <%@ page language="java" contentType="text/html;charset=UTF-8"%>  

  2. >  

  3. <html>  

  4.   <head>  

  5.     <title>json 返回列表处理title>  

  6.     <script language="javascript">  

  7.         var xmlHttp = false;  

  8.         try{  

  9.             xmlHttp = new ActiveXObject("msxml2.XMLHTTP");  

  10.         }catch(e1){  

  11.             try{  

  12.                 xmlHttp = new ActiveXObject("microsoft.XMLHTTP");  

  13.             }catch(e2){  

  14.                 try{  

  15.                     xmlHttp = new XMLHttpRequest();  

  16.                 }catch(e3){  

  17.                     xmlHttp = false;  

  18.                 }  

  19.             }  

  20.         }  

  21.         if(!xmlHttp){  

  22.             alert("create xmlHttpRequest fail");  

  23.         }  

  24.         function jsonListResult(){  

  25.             xmlHttp.onreadystatechange = function(){  

  26.                 if(xmlHttp.readyState == 4) {  

  27.                     var userList = eval('(' + xmlHttp.responseText + ')');  

  28.                     var user = eval(userList.JSONRESULT);  

  29.                     var result = "";  

  30.                     result += "<tr><td>userIdtd><td>userNametd><td>sextd>tr>";  

  31.                     for(var i=0;i<user.length;i++) {  

  32.                         result += "<tr>";  

  33.                         result += "<td>"+user[i].userId +"td>";  

  34.                         result += "<td>"+user[i].userName+"td>";  

  35.                         result += "<td>"+user[i].sex+"td>";  

  36.                         result += "tr>";  

  37.                     }  

  38.                     result += "table>";  

  39.                     document.getElementById('jsonDiv').innerHTML = result;  

  40.                 }  

  41.             }  

  42.             xmlHttp.open("POST","jsonlist.action",true);  

  43.             xmlHttp.send(null);  

  44.         }  

  45.     script>  

  46.   head>  

  47.   <body>  

  48.     <div id="jsonDiv">div>  

  49.     <input type="button" value="show list" onclick="jsonListResult();">  

  50.   body>  

  51. html>  

转自:http://ctojxzsycztao.javaeye.com/blog/390949