struts.xml:
<action name="postTest" class="action.testAction" method="postTest">
<result name="postSuccess" type="json">
<param name="root">ok</param>
</result>
</action>
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";
}
网友评论