欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ajax后台处理返回json值示例代码

程序员文章站 2022-06-04 23:13:02
复制代码 代码如下: public actionforward xsearch(actionmapping mapping, actionform form, httpse...
复制代码 代码如下:

public actionforward xsearch(actionmapping mapping, actionform form,
httpservletrequest request, httpservletresponse response)
throws exception {
string parentid = request.getparameter("parentid");
string supplier = request.getparameter("supplier");
list itemlist = new arraylist();
if(parentid.equals("")){
parentid="0";
}
map map=new tawaptreeservlet().gettypelist(parentid, supplier);

for (iterator rowit = map.keyset().iterator(); rowit.hasnext();) {
string id = (string) rowit.next();
tawcommonsuilistitem uiitem = new tawcommonsuilistitem();
uiitem.setitemid(id);
uiitem.settext((string)map.get(id));
uiitem.setvalue(id);
itemlist.add(uiitem);
}

response.setcontenttype("text/xml;charset=utf-8");

// 返回json对象
response.getwriter().print(jsonutil.list2json(itemlist));
return null;
}