日期:2014-05-17  浏览次数:20758 次

关于ExtJS servlet问题,急急急!!!
自己做个小例子,怎么前台页面显示不出来数据,好像也进不了后台的servlet,请教什么原因?
后台servlet代码:
public class DataServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("GBK");
request.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
out.write("{\"provincelist\":[{\"id\":1,\"province\":\"河南省\"},{\"id\":2,\"province\":\"河北省\"},{\"id\":3,\"province\":\"山西省\"},{\"id\":4,\"province\":\"山东省\"},{\"id\":5,\"province\":\"湖南省\"},{\"id\":6,\"province\":\"湖北省\"},{\"id\":7,\"province\":\"四川省\"},{\"id\":8,\"province\":\"辽宁省\"},{\"id\":9,\"province\":\"吉林省\"},{\"id\":10,\"province\":\"黑龙江省\"},{\"id\":11,\"province\":\"广东省\"},{\"id\":12,\"province\":\"浙江省\"},{\"id\":13,\"province\":\"福建省\"},{\"id\":14,\"province\":\"甘肃省\"},{\"id\":15,\"province\":\"江西省\"},{\"id\":16,\"province\":\"陕西省\"},{\"id\":17,\"province\":\"海南省\"},{\"id\":18,\"province\":\"江苏省\"},{\"id\":19,\"province\":\"安徽省\"},{\"id\":20,\"province\":\"云南省\"},{\"id\":21,\"province\":\"贵州省\"},{\"id\":22,\"province\":\"天津市\"},{\"id\":23,\"province\":\"北京市\"},{\"id\":24,\"province\":\"上海市\"},{\"id\":25,\"province\":\"重庆市\"},{\"id\":26,\"province\":\"新疆维吾尔族自治区\"},{\"id\":27,\"province\":\"内蒙古自治区\"},{\"id\":28,\"province\":\"西藏自治区\"},{\"id\":29,\"province\":\"广西壮族自治区\"},{\"id\":30,\"province\":\"宁夏回族自治区\"},{\"id\":31,\"province\":\"香港特别行政区\"},{\"id\":32,\"province\":\"澳门特别行政区\"}]}");
out.flush();
out.close();

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}

前台jsp代码:
Ext.onReady(function(){
var store=new Ext.data.JsonStore({
autoLoad:true,
url:"/dataServlet.do", 
root:"provincelist",
fields:["id","province"]
});
//定义列
var colM=new Ext.grid.ColumnModel([{header:"序号",dataIndex:"id"},
{header:"省市",dataIndex:"province"}]);

//数据源定义,创建表格
var grid = new Ext.grid.GridPanel({

renderTo:Ext.getBody(),

title:"表格测试",

height:200,

width:600, 

cm:colM,

store:store

}); 

});

web.xml中配置:
<servlet>
  <servlet-name>DataServlet</servlet-name>
  <servlet-class>CPlib.ajax.DataServlet</servlet-class>
 </servlet>
<servlet-mapping>
  <