前台数据{ id:'user_update', text: '编辑', maxWidth:55, handler:function(){ var user_form = this.up('form'); if(user_form.getForm().isValid()){ user_form.getForm().submit({ // url: 'updateUserServlet', url:'MyJsp.jsp',
                            method:'post', 
                            
                            submitEmptyText: false, 
                            waitTitle:'请等待', 
                            waitMsg: '正在编辑用户...', 
                            params : { 
                                id : userid, 
                                userName : userName, 
                                userPermiss : userPermiss, 
                                description : description, 
                                userPasswd : userPasswd 
                            }, 
                            
                            success:function(form,action){ 
                                var response = Ext.decode(action.response.responseText); 
                                Ext.Msg.alert('提示', response.msg); 
                                userStore.load(); 
                            }, 
                            failure:function(form,action){ 
                                Ext.Msg.alert('提示', '编辑用户失败!'); 
                            } 
                        }); 
                    }else{ 
                        Ext.Msg.alert('提示', '数据验证失败!'); 
                    } 
                } 
            } 
 
后台代码:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.BufferedReader" %> <%@ page import="net.sf.json.*" %> <% BufferedReader in=request.getReader(); StringBuffer jsonStr=new StringBuffer(); String str=""; while((str=in.readLine())!=null){ jsonStr.append(str); } JSONObject jsonObj= JSONObject.fromObject(jsonStr.toString()); String name= jsonObj.getString("userName");
String msg=""; out.print("asdf"); out.print(name);
%> 服务器报错为:严重: Servlet.service() for servlet jsp threw exception net.sf.json.JSONException: A JSONObject text must begin with '{' at character 1 of id=3&userName=yy&userPermiss=3&description=&userPasswd=usd1111 经过打印后,得到的数据为id=3&userName=yy&userPermiss=3&description=&userPasswd=usd1111不是json格式,请问哪里有问题??
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
用最简单的方式啊,你的代码太复杂了
Java代码 收藏代码
Enumeration<String> em=request.getParameterNames();  
String pm="";  
JSONObject jsonObj = new JSONObject();  
while(em.hasMoreElements()){  
    pm = em.nextElement();  
    jsonObj.put(pm, request.getParameter(pm));  
}  
  
String name= jsonObj.getString("userName");