ExtJs读取servlet传送数据
EXTJS
application.js
Ext.onReady(function() { // var data = [{ // name : ‘唐伯虎‘, // age : 25, // sex : ‘男‘ // }, { // name : ‘楚留香‘, // age : 24, // sex : ‘女‘ // }]; var ds = new Ext.data.JsonStore({ proxy : new Ext.data.HttpProxy({ url : ‘dataList‘// 相对路径 }), root : ‘ ‘, fields : [{ name : ‘name‘ }, { name : ‘age‘ }, { name : ‘sex‘ }] }); // ds.loadData(data); var grid = new Ext.grid.GridPanel({ viewConfig : { forceFit : true }, store :ds, columns : [{ header : ‘姓名‘, dataIndex : ‘name‘ }, { header : ‘年龄‘, dataIndex : ‘age‘ }, { header : ‘出生日期‘, 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:‘唐伯虎‘,age:25,sex:‘男‘},{name:‘楚留香‘,age:24,sex:‘女‘}]"; //_str ="[{name:‘唐伯虎‘,age:25,sex:‘男‘},{name:‘楚留香‘,age:24,sex:‘女‘}];" ; response.getWriter().write(_str); // request.setAttribute("ooo", _str); // request.getRequestDispatcher("datawrite.jsp").forward(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } }web.xml
<servlet> <description></description> <display-name>dataList</display-name> <servlet-name>dataList</servlet-name> <servlet-class>com.ext.servlet.dataList</servlet-class> </servlet> <servlet-mapping> <servlet-name>dataList</servlet-name> <url-pattern>/dataList</url-pattern> </servlet-mapping> <servlet>
前台测试路径
http://localhost:8080/ExtJsApplication/index.html
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。