struts2接收JSON字符串

struts.xml:


        
            ok 
        

js代码如下:

$("#b3").click(function(){
    $.post({
        url:'postTest',
        //data:"name="+JSON.stringify(user),
        data:{"name":"小李","age":10},
        datatype:'json',
        success:function(data){
            console.log(data);
        }
    })
})

testAction代码如下,注意属性必须有getter和setter

private String name;
private String age;
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getAge() {
    return age;
}
public void setAge(String age) {
    this.age = age;
}
public String postTest(){       
    System.out.println(this.name);
    System.out.println(this.age);
    return "postSuccess";
}

你可能感兴趣的:(struts2接收JSON字符串)