Copy codeThe Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Insert title here </title>
<Link rel = "stylesheet" type = "text/css" href = "easyui/themes/default/easyui.css">
<Link rel = "stylesheet" type = "text/css" href = "easyui/themes/icon.css">
<Script type = "text/javascript" src = "easyui/jquery-1.8.0.min.js"> </script>
<Script type = "text/javascript" src = "easyui/jquery. easyui. min. js"> </script>
</Head>
<Body>
<Table id = "dg" title = "My Users" class = "easyui-datagrid" style = "width: 500px; height: 250px"
Url = "getUsers. jsp"
Toolbar = "# toolbar" rownumbers = "true"
FitColumns = "true" singleSelect = "true">
<Thead>
<Tr>
<Th field = "firstname" width = "50"> First Name </th>
<Th field = "lastname" width = "50"> Last Name </th>
<Th field = "phone" width = "50"> Phone </th>
<Th field = "email" width = "50"> Email </th>
</Tr>
</Thead>
</Table>
</Body>
</Html>
Copy codeThe Code is as follows:
<% @ Page import = "net. sf. json. JSONArray" %>
<% @ Page import = "java. util. *" %>
<% @ Page import = "org. codehaus. jackson. map. ObjectMapper" %>
<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Insert title here </title>
</Head>
<Body>
<%
// String json = "{\" firstname \ ": \" firstname \ ", \" lastname \ ": \" lastname \ ", \" phone \ ": 123456, \ "email \": \ "281446883@qq.com \"}";
List <Map <String, String> list = new ArrayList <Map <String, String> ();
Map <String, String> user1 = new HashMap <String, String> ();
User1.put ("firstname", "name1 ");
User1.put ("lastname", "name2 ");
User1.put ("phone", "1234 ");
User1.put ("email", "281446888@qq.com ");
List. add (user1 );
Map <String, String> user2 = new HashMap <String, String> ();
User2.put ("firstname", "name2 ");
User2.put ("lastname", "name4 ");
User2.put ("phone", "1234 ");
User2.put ("email", "281446888@qq.com ");
List. add (user2 );
JSONArray jsonArray = JSONArray. fromObject (list );
System. out. println (jsonArray. toString ());
Map <String, Object> map = new HashMap <String, Object> ();
Map. put ("total", 1 );
Map. put ("rows", jsonArray );
ObjectMapper objMap = new ObjectMapper ();
ObjMap. writeValue (response. getWriter (), map );
// System. out. println (json );
%>
</Body>
</Html>
Effect: