Servlet中的List:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ext e = new ext();
List<User> l = e.page2(0, 3);
JSONArray jsonArray = Test3.getListjsonArray(l);
response.setContentType("text/json;charset=UTF-8");// 设置数据到前台显示的字符编码,如果不转会有乱码
response.getWriter().print(jsonArray);
System.out.println(jsonArray);
}      怎样让他显示在jsp页面?  急求大哥大姐些帮助啊!!!
    

解决方案 »

  1.   

    这个问题楼主不应该问 作为Ext+Java 这属于基本技能
    前台Grid都有store 里边定义了固定的数据格式 你的后台应该返回相应的格式
    好好利用搜索引擎吧~~
      

  2.   

        如果没有分页的话 
          后台返回  
    String result = JSONArray.fromObject(jsonArray ).toString();
    //String str = "{totalProperty:" + size + ",data:"
    + JSONArray.fromObject(list).toString() + "}"; //用于分页
    response.getWriter().print(result );var store = new Ext.data.JsonStore({
    url:url,
                    //root:'data',//注释两行用于分页的
    //totalProperty:"totalProperty",
            fields:fields,
    pruneModifieRecords:true //store每次提交后自动清除modified标记
    });
    store.load();
    基本上就这样了。    
      

  3.   


        
            我写成这样了。。但是还是不行?、   还请帮忙看哈public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    ext e = new ext();
    List<User> l = e.page2(0, 3);
    JSONArray jsonArray = Test3.getListjsonArray(l);
    String result = JSONArray.fromObject(jsonArray ).toString();
    response.setContentType("text/json;charset=UTF-8");// 设置数据到前台显示的字符编码,如果不转会有乱码
    response.getWriter().print(result);
    System.out.println(result);
    }前台
    <script type="text/javascript">
    Ext.onReady(function() {
    var store = new Ext.data.JsonStore( {
    url:"extjsController",
    root:"result",
        fileds:['id','name','sex'],
        pruneModifieRecords:true     
           });
        store.load();
    var grid = new Ext.grid.GridPanel( {
    renderTo : "hello",
    title : "json列表",
    height : 150,
    width : 600,
    columns : [ {
    header : "编号",
    dataIndex : "id"
    }, {
    header : "姓名",
    dataIndex : "name"
    }, {
    header : "性别",
    dataIndex : "sex"
    } ],
    store : store,
    autoExpandColumn : 2
    });
    });
    </script>
    </head>
    <body>
    <div id="hello" align="center">
      midjhfuird
    </div>
    </body>
      结果只有显示这个表格没有数据库中读取出来的内容
             
      

  4.   

    extjsController 这个是什么请求?
      

  5.   

       就是后台返回json码的Servlet
      

  6.   

      请求最好 加上项目名称/项目名/请求
      没有发现你的servlet请求前面有斜杠。。