日期:2014-05-16  浏览次数:20368 次

ScriptTagProxy与jsp后台交互实例
ScriptTagProxy与jsp后台交互实例
---->js
Ext.onReady(function(){
	var personRecord = new Ext.data.Record.create([
		{name:"name",type:"string"},
		{name:"sex",type:"string"}
	])

	var pDate = new personRecord({name:"steven",sex:"boy"});
	var store = new Ext.data.Store({
//		proxy:new Ext.data.HttpProxy({url:"http://localhost:8080/extTest/data.jsp"}),
		proxy:new Ext.data.ScriptTagProxy({url:"http://192.188.60.97:8080/extTest/data.jsp"}),
		reader: new Ext.data.ArrayReader({},personRecord)
	})
	 store.load();
	 
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            {header: 'name', dataIndex: 'name'},
            {header: 'sex', dataInex: 'sex'}
        ],
        autoHeight: true,
        renderTo: 'grid'
    });
    
});


------>jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%
boolean flag = false;
	String cbStr = request.getParameter("callback");
	if(cbStr != null){
		flag = true;
		response.setContentType("text/javascript");
		out.print(cbStr+"(");
	}else{
		response.setContentType("application/x-json");
	}
	out.print("[" +
	           "['jim','boy']," +
	           "['tom','boy']," +
	           "['kit','girl']" +
	           "]"
	);
	if(flag){
		out.print(");");
	}
	System.out.println(cbStr);
%>



注意:out.print(cbStr+"(");一定要返回cbStr,否则不会出结果。
1 楼 gbj_2008 2011-12-28  
不行啊,不能运行啊大哥