• Ext.grid.EditorGridPanel保存


    用get方法传递编辑的数据会出现乱码,解决get乱码的方法就是encodeURI(param),然后在后台转码:

            String strJson =  new String(request.getParameter("param").getBytes("iso-8859-1"),"utf-8");  
            java.net.URLDecoder.decode(strJson, "UTF-8");

    下面是get方法传参代码:

    1、获取Ext.grid.EditorGridPanel的bbar添加保存按钮

     1 bbar:new Ext.PagingToolbar({
     2              emptyMsg:"没有数据",
     3              displayInfo:true,
     4              displayMsg:"目前显示第 {0} - {1} 条,共 {2} 条",
     5              store:store,
     6              pageSize:20,
     7              refreshText:"刷新列表",
     8              items:['-', {
     9                 text:'保存',
    10                 handler:function(){
    11                         var m = store.modified.slice(-1);  
    12                         var jsonArray = []; //定义修改后的JSON对象  
    13                     Ext.each(m, function (item) {
    14                             jsonArray.push(item.data);  
    15                     });   
    16                     var strJson = Ext.encode(jsonArray);
    17                     if (jsonArray.length == 0) {  
    18                             Ext.Msg.alert('提示', '没有对数据进行任何更改!');  
    19                         return;  
    20                     }else{
    21                         Ext.Msg.alert('提示', '保存!'); 
    22                         Ext.Ajax.request({  
    23                             url: '/s.do/servlet?tg=s&json='+ encodeURI(strJson), 
    24                             success: function (response) {  
    25                                 Ext.Msg.alert("提交成功", response.responseText); //必须返回json类型   context.Response.Write("{ success: true, errors:{} }");  
    26                             },  
    27                             failure: function (response) {  
    28                                 Ext.Msg.alert("提交失败", response.responseText); //必须返回json类型{ success: false, errors:{info: '错误了'} }  
    29                             } 
    30                         });  
    31                     }
    32                 }
    33             }]
    34          })
    get

    2、后台解析json

     1 String strJson =     new String(request.getParameter("json").getBytes("iso-8859-1"),"utf-8");  
     2         java.net.URLDecoder.decode(strJson, "UTF-8");
     3         System.out.println(strJson);
     4         JSONArray js=JSONArray.fromObject(strJson);
     5         JSONObject json = null;
     6         Iterator it=js.iterator();
     7           while(it.hasNext()){
     8               json=(JSONObject)it.next();
     9                String nbbm=json.getString("nbbm");
    10                int flag = json.getInt("flag");
    11           }
    get/servlet

     下面是post方式传参,推荐这种方法,无须转码:

     1         bbar:new Ext.PagingToolbar({
     2              emptyMsg:"没有数据",
     3              displayInfo:true,
     4              displayMsg:"目前显示第 {0} - {1} 条,共 {2} 条",
     5              store:store,
     6              pageSize:20,
     7              refreshText:"刷新列表",
     8              items:['-', {
     9                 text:'保存',
    10                 handler:function(){
    11                     var m = store.modified.slice(-1);  
    12                     var jsonArray = []; //定义修改后的JSON对象  
    13                     Ext.each(m, function (item) {//将修改后的行对象生成json对象  
    14                         jsonArray.push(item.data);  
    15                     });   
    16                     var strJson = Ext.encode(jsonArray);
    17                     if (jsonArray.length == 0) {  
    18                             Ext.Msg.alert('提示', '没有对数据进行任何更改!');  
    19                         return;  
    20                     }else{
    21                         Ext.Msg.alert('提示', '保存!'); 
    22                         Ext.Ajax.request({  
    23                             url: '/servlet/AccountManagement?action=save', 
    24                             success: function (response) {  
    25                                 Ext.Msg.alert("提交成功", response.responseText); //必须返回json类型   context.Response.Write("{ success: true, errors:{} }");  
    26                             },  
    27                             failure: function (response) {  
    28                                 Ext.Msg.alert("提交失败", response.responseText); //必须返回json类型{ success: false, errors:{info: '错误了'} }  
    29                             },  
    30                             params: { UpdateInfo: Ext.encode(jsonArray)}//参数使用 Ext.encode方法将JSON对象编码成字符串,传递到后台!!!!!!  
    31                         });  
    32                     }
    33                 }
    34             }]
    35          })
    post

    后台解析json:

     1 String strJson = request.getParameter("UpdateInfo");
     2 System.out.println(strJson);
     3 JSONArray js=JSONArray.fromObject(strJson);
     4 JSONObject json = null;
     5 Iterator it=js.iterator();
     6 while(it.hasNext()){
     7     json=(JSONObject)it.next();
     8     String nbbm=json.getString("nbbm");
     9     int flag = json.getInt("flag");
    10 }
    post/servlet
  • 相关阅读:
    python爬虫之Scrapy框架
    Web自动化测试工具:Selenium
    多线程爬取新闻标题和链接
    python里更推荐使用的requests库
    python豆瓣的简单爬虫
    4 个好用的 Linux 监控工具
    8个你会爱上的 VS Code 扩展
    SpringBoot 构建 Docker 镜像的 3 种方式
    OAuth2 图解
    Prometheus + Grafana 监控 SpringBoot
  • 原文地址:https://www.cnblogs.com/zhutouying/p/3267230.html
Copyright © 2020-2023  润新知