java - Send JSON by ajax and get parameters by request in JSP -


i need send json object ajax (with jquery) , parameters request object in jsp (server side).

my js code is:

        var request = new object();         request.param1= "value1";         request.param2 = "value2";         $.ajax({         type:'get',         url: 'test.jsp',         //data: {request:json.stringify(datasend)},         //data: {request:datasend},         //data: json.stringify(request),         data:request,         async:true,         success:function(r){             console.log(r);         },         error:function(error){             console.log(error);         }     }); 

and jsp code is:

<%@page import="cl.test.pos.web.delegate.posxxxxxxxx"%> <%@page import="org.json.simple.jsonobject"%> <%  jsonobject j = new jsonobject(); if(session.getattribute("role") != null ){     posxxxxxxxx bx = new posxxxxxxxx();     string je;     je = bx.settest(request);     out.print(je);     out.close(); }else{     j.put("responsestatus","exception");     request.getsession().invalidate();      out.print(j);     out.close(); } %> 

and method class is

    public string settest(httpservletrequest request) throws ioexception{     jsonobject j = new jsonobject();     try{         j.putall(request.getparametermap());         j.put("responsestatus", "ok");     }catch(frameworkexception e){         /*any code*/     }catch(throwable t){         /*any code*/     }     return j.tojsonstring();     } 

i expect return json object on client , so, but, response this:

{"param1":[ljava.lang.string;@182f12f,"param2":[ljava.lang.string;@1a881f5}

values not understandable , if send objects , arrays, wrong too, example:

{"parametro4[1][p3]":[ljava.lang.string;@c5954b,"parametro4[1][p4]":[ljava.lang.string;@1cc9339,"parametro5[arr1][]":[ljava.lang.string;@1d5af30}

please me parameters on jsonobject httpservletrequest. need know best way this.

(i searched in stackoverflow , surfing in web, , cannot found best way this).

the parametermap value array object , not string:

returns: immutable java.util.map containing parameter names keys , parameter values map values. keys in parameter map of type string. the values in parameter map of type string array.

javadoc getparametermao

so need code it, iterate throught map , put parameter name/value in object.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -