搞了两天了没搞通,各位高手是否有例子给一个?//我的代码如下,不知道错在哪里,请指教//Action中生成JSON
public ActionForward ypurchplanquery_d(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
try{
ExtDataChange extDataChange = new ExtDataChange(); String aparam = (String) request.getParameter("ypurchplanquery_d");
List lst = ypurchplandao.GetYPurchPlanInfo(aparam);
// System.out.println(extDataChange.getJsonFromList(lst));
String jsonstr = extDataChange.getJsonFromList(lst);
response.setContentType("text/json; charset=GBK");
response.getWriter().write(jsonstr);
// System.out.println("输出到前台的JSON字符串是:" + jsonstr);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("error", "年采购计划查看失败");
return mapping.findForward("error");
}
return mapping.findForward("ypurchplanquery_d");
}//生成的结果输出到前台的JSON字符串是:{"items":[{"carStyle":"carstyle","guid":"9A9DC4D1-05B8-4B80-81B6-4E604164B1D3","m1":1,"m10":10,"m11":11,"m12":12,"m2":2,"m3":2,"m4":3,"m5":5,"m6":6,"m7":7,"m8":8,"m9":9,"planNo":"1","poNum":1,"productDesc":"ooo","productId":"001","productName":"02323","re":"125636","syear":2010},{"carStyle":"carstyle","guid":"492AA1C7-753B-40EB-8AE6-7DDED9775802","m1":1,"m10":10,"m11":11,"m12":12,"m2":2,"m3":2,"m4":3,"m5":5,"m6":6,"m7":7,"m8":8,"m9":9,"planNo":"1","poNum":1,"productDesc":"ooo","productId":"001","productName":"02323","re":"125636","syear":2010}],"results":2}
//在Ext的JS中是这样定义的
var store = new Ext.data.Store({
// destroy the store if the grid is destroyed
// autoDestroy: true,
// load remote data using HTTP
// url: 'ypurchplan.do?action=ypurchplanquery_d',
// proxy: new Ext.data.HttpProxy({
// method:"POST"
// }),
// specify a XmlReader (coincides with the XML format of the returned data)
reader: new Ext.data.JsonReader({
url: "ypurchplan.do?action=ypurchplanquery_d",
root: 'items',
totalProperty: 'results',
autoload: true,
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'poNum', type: 'string'},
{name: 'carStyle', type: 'string'},
{name: 'productID', type: 'string'},
{name: 'productName', type: 'string'},
{name: 'productDes', type: 'string'},
{name: 'syear', type: 'int'},
{name: 'm1', type: 'int'},
{name: 'm2', type: 'int'},
{name: 'm3', type: 'int'},
{name: 'm4', type: 'int'},
---------------------------
请高手指教?
public ActionForward ypurchplanquery_d(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
try{
ExtDataChange extDataChange = new ExtDataChange(); String aparam = (String) request.getParameter("ypurchplanquery_d");
List lst = ypurchplandao.GetYPurchPlanInfo(aparam);
// System.out.println(extDataChange.getJsonFromList(lst));
String jsonstr = extDataChange.getJsonFromList(lst);
response.setContentType("text/json; charset=GBK");
response.getWriter().write(jsonstr);
// System.out.println("输出到前台的JSON字符串是:" + jsonstr);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("error", "年采购计划查看失败");
return mapping.findForward("error");
}
return mapping.findForward("ypurchplanquery_d");
}//生成的结果输出到前台的JSON字符串是:{"items":[{"carStyle":"carstyle","guid":"9A9DC4D1-05B8-4B80-81B6-4E604164B1D3","m1":1,"m10":10,"m11":11,"m12":12,"m2":2,"m3":2,"m4":3,"m5":5,"m6":6,"m7":7,"m8":8,"m9":9,"planNo":"1","poNum":1,"productDesc":"ooo","productId":"001","productName":"02323","re":"125636","syear":2010},{"carStyle":"carstyle","guid":"492AA1C7-753B-40EB-8AE6-7DDED9775802","m1":1,"m10":10,"m11":11,"m12":12,"m2":2,"m3":2,"m4":3,"m5":5,"m6":6,"m7":7,"m8":8,"m9":9,"planNo":"1","poNum":1,"productDesc":"ooo","productId":"001","productName":"02323","re":"125636","syear":2010}],"results":2}
//在Ext的JS中是这样定义的
var store = new Ext.data.Store({
// destroy the store if the grid is destroyed
// autoDestroy: true,
// load remote data using HTTP
// url: 'ypurchplan.do?action=ypurchplanquery_d',
// proxy: new Ext.data.HttpProxy({
// method:"POST"
// }),
// specify a XmlReader (coincides with the XML format of the returned data)
reader: new Ext.data.JsonReader({
url: "ypurchplan.do?action=ypurchplanquery_d",
root: 'items',
totalProperty: 'results',
autoload: true,
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'poNum', type: 'string'},
{name: 'carStyle', type: 'string'},
{name: 'productID', type: 'string'},
{name: 'productName', type: 'string'},
{name: 'productDes', type: 'string'},
{name: 'syear', type: 'int'},
{name: 'm1', type: 'int'},
{name: 'm2', type: 'int'},
{name: 'm3', type: 'int'},
{name: 'm4', type: 'int'},
---------------------------
请高手指教?
解决方案 »
- mybatis配置文件中怎样写创建和删除视图的sql语句啊
- 用installanywhere 把web程序及tomcat和Access安装到用户机器上,并且自动注册为服务并启动
- java工作面试
- 急!jsp从数据库中读出图像问题!在线等!
- 为什么我在struts里struts-config文件配置里实现不了页面的转向
- 帮看看java打印的代码,那里错了?
- jsp的问题,去掉字符串两边多余的空格
- 请问怎样把查询的内容写入指定的文件中?
- 请问这几本JSP的书哪本不错???(已有JAVA基础和入门的书)
- JSP与Java Bean 的问题大家帮忙看看!!在线等待!!急!
- web service发布和调用思路?
- 用MyEclipse 写JSP时,<font><p></p></font>警告
return mapping.findForward("ypurchplanquery_d"); return null就可以了