EXTJS
Application. js
Ext. onReady (function () {// var data = [{// name: 'tang bohu ', // age: 25, // sex: 'male '//}, {// name: 'chu Liuxiang ', // age: 24, // sex: 'female' //}]; var ds = new Ext. data. jsonStore ({proxy: new Ext. data. httpProxy ({url: 'datalist' // relative path}), root: '', fields: [{name: 'name'}, {name: 'age '}, {name: 'sex'}]}); // ds. loadData (data); var grid = new Ext. grid. gridPanel ({viewConfig: {forceFit: true}, store: ds, columns: [{header: 'name', dataIndex: 'name'}, {header: 'age ', dataIndex: 'age'}, {header: 'birthdate ', dataIndex: 'sex'}]}); var win = new Ext. window ({title: 'httpproxy', width: 400, height: 300, layout: 'fit ', items: grid}); ds. load (); win. show ();});
Servlet
DataList. java
Package com. ext. servlet; import java. io. IOException; import java. io. outputStream; import java. io. printStream; import java. io. printWriter; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import net. sf. json. JSONArray; import net. sf. json. JSONObject; import org. apache. jasper. tagplugins. jstl. core. out;/*** Servlet implementation class dataList */public class dataList extends HttpServlet {private static final long serialVersionUID = 1L;/*** @ see HttpServlet # HttpServlet () */public dataList () {super (); // TODO Auto-generated constructor stub}/*** @ see HttpServlet # doGet (HttpServletRequest request, HttpServletResponse response) */protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stub // response. setContentType ("text/html"); response. setCharacterEncoding ("UTF-8"); String _ str = "[{name: 'tang bohu ', age: 25, sex: 'male'}, {name: 'chu Liuxiang', age: 24, sex: 'female '}] "; // _ str =" [{name: 'tang bohu', age: 25, sex: 'male'}, {name: 'chu Liuxiang ', age: 24, sex: 'female'}]; "; response. getWriter (). write (_ str); // request. setAttribute ("ooo", _ str); // request. getRequestDispatcher ("datawrite. jsp "). forward (request, response);}/*** @ see HttpServlet # doPost (HttpServletRequest request, response) */protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}}
Web. xml
dataList
dataList
com.ext.servlet.dataList
dataList
/dataList
Foreground test path
Http: // localhost: 8080/ExtJsApplication/index.html