dojox.grid.DataGrid显示数据的方法(转)

第一种:数据存在本地或者已经写死的JSON对象中,不需要跟服务端进行数据传输

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"  
 2     pageEncoding="UTF-8"%>  
 3   
 4   
 5   
 6   
 7 Insert title here  
 8   
 9   
10   
11   
12   
13   
51   
52   
53   
54   
55 
56 57 58 59 60

第二种:数据来源于服务器端

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"  
 2     pageEncoding="UTF-8"%>  
 3   
 4   
 5   
 6   
 7 Insert title here  
 8   
 9   
10   
11   
12   
13   
27   
28   
29   
30   
31 
dojox.grid.DataGrid Basic Test
32 33 34 jsId="jsonStore" url="../WriteJson"> 35 36 37 38 jsid="grid" id="grid" 39 store="jsonStore" query="{ name: '*' }" rowsPerPage="1" rowSelector="20px"> 40414243444546
Country/Continent Name Type
47 48 49

服务端后台代码:

 1 package hb.servlet;  
 2   
 3 import java.io.IOException;  
 4 import java.io.PrintWriter;  
 5   
 6 import javax.servlet.ServletException;  
 7 import javax.servlet.http.HttpServlet;  
 8 import javax.servlet.http.HttpServletRequest;  
 9 import javax.servlet.http.HttpServletResponse;  
10   
11 /** 
12  * Servlet implementation class WriteJson 
13  */  
14 public class WriteJson extends HttpServlet {  
15     private static final long serialVersionUID = 1L;  
16          
17     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
18         this.doPost(request, response);  
19     }  
20   
21     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
22         System.out.println("{items:[{name:'Africa', type:'continent'},{name:'Africa1', type:'continent1'}]}");  
23         PrintWriter pw = response.getWriter();  
24         pw.write("{items:[{name:'Africa', type:'continent'},{name:'Africa1', type:'continent1'},{name:'Africa1', type:'continent1'},{name:'Africa1', type:'continent1'},{name:'Africa1', type:'continent1'}]}");  
25         pw.flush();  
26         pw.close();  
27     }  
28   
29 }  

注:本文转载于http://hbiao68.iteye.com/blog/1683875,感谢原文作者!

转载于:https://www.cnblogs.com/GISQZC/p/6822055.html

你可能感兴趣的:(dojox.grid.DataGrid显示数据的方法(转))