使用JSON,在SERVLET或者STRUTS的ACTION中取得数据时,如果会出现异常:java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
是因为需要的类没有找到,一般,是因为少导入了JAR包,
使用JSON时,除了要导入JSON网站上面下载的json-lib-2.2-jdk15.jar包之外,还必须有其它几个依赖包:commons-beanutils.jar,commons-httpclient.jar,commons-lang.jar,ezmorph.jar,morph-1.0.1.jar
这几个包也是需要导入的.如果缺少里面的:ezmorph.jar包,则即出现上述异常
commons系列的包,可在网站:http://www.docjar.com/上面搜索下载,其它包可下载网站如下:
http://json-lib.sourceforge.net/
http://morph.sourceforge.net/
http://ezmorph.sourceforge.net/
那么怎么从后台传数据到前台呢:
action里
JSONObject json = new JSONObject();
json.put("result", list);
json.put("totalCount", list.size());
System.out.println("-------------="+json.toString());
HttpServletResponse response = ServletActionContext.getResponse();
// 编制响应的格式
response.setContentType("text/html;charset=UTF-8");
try {
response.getWriter().write(json.toString());
} catch (IOException e) {
e.printStackTrace();
}
return null;
前台mygrid.js:
ListGridPanel=function(viewer,config){
Ext.apply(this,viewer);
this.init(config);
ListGridPanel.superclass.constructor.call(this,{
});
};
Ext.extend(ListGridPanel,Ext.grid.GridPanel,{
init:function(config){
var col=[];
var rcol=[];
for(var i=0,j=config.columns;i<j.length;i++){
if(j[i]["dataIndex"]!=""){
col.push(j[i]);
rcol.push({name:j[i]["dataIndex"]});
}
}
this.columns=col;
alert("我来了数据="+config.url);
var store = new Ext.data.Store({
url:config.url,
baseParams:{method:config.method,limit:10,start:0},
reader:new Ext.data.JsonReader({totalProperty: 'totalCount',root:"result"},Ext.data.Record.create(rcol)),
autoLoad:true
});
this.store = store,
this.region='center',
this.loadMask=true,
this.bbar= new Ext.PagingToolbar({store:store,pageSize:10,displayMsg:'显示第 {0} 条到 {1} 条记录,一共 {2} 条', emptyMsg:'没有记录'});
}
});
自己的jsp:
var usercheckbox =new Ext.grid.CheckboxSelectionModel();
var userrownumber=new Ext.grid.RowNumberer();
var widthValue=61;
var yoyo = "123";
//权限表头
var purview=[usercheckbox,userrownumber,
{header:'应用提供商编号',dataIndex:'bpid',sortable:true},
{header:'服务名称',dataIndex:'bsName',sortable:true},
{header:'密码',dataIndex:'password',sortable:true},
{header:'用系统名称',dataIndex:'userName',sortable:true}
];
var config={columns:purview,url:'<%=basePath%>/AdminLogin/login/adminLoginAction_loginQueryUserList',method:'loginQueryUserList'};
var gridpanel=new ListGridPanel({height:500,width:1200,sm:usercheckbox,id:"grid"},config);
记得:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript"
src="<%=basePath%>/AdminLogin/common/ext/ext-base.js"></script>
<script type="text/javascript"
src="<%=basePath%>/AdminLogin/common/ext/ext-all.js"></script>
<link rel="stylesheet" type="text/css"
href="<%=basePath%>/AdminLogin/common/ext/resources/css/ext-all.css" />
<script type="text/javascript"
src="<%=basePath%>/AdminLogin/common/myGrid.js"></script>
<script type="text/javascript"