我写的一个用到josn插件的程序,
action里是这样写的
class Student{
private Integer id;
private String name;
private Date birthday;
// getter and setter
}class StudentAction extends ActionSupport{ private Student stu; public String saveStudent(){
System.out.println(stu.getId());
System.out.println(stu.getName());
System.out.println(stu.getBirthday());
//some code about saving student object
}
//stu setter and setter
}struts的配置文件是这样的
<package name="student" extends="json-default">
<action name="StudentAction" class="com.StudentAction" method="saveStudent">
<result type="json">
</result>
</action>
</package>客户端的javascript是这样的
//用的是jQuery
var stu = {'id':100,'name':'张三','birthday':new Date()};
$.getJSON('StudentAction.action',{'stu':stu},function(data){
//some code
});
运行之后控制台一直报以下问题com.opensymphony.xwork2.interceptor.ParametersInterceptor - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'stu[id]' on 'class com.StudentAction: Error setting expression 'stu[id]' with value '[Ljava.lang.String;@10933e7'com.opensymphony.xwork2.interceptor.ParametersInterceptor - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'stu[name]' on 'class com.StudentAction: Error setting expression 'stu[name]' with value '[Ljava.lang.String;@1f2509c'
打印的三个属性也是null
毛哦,这是啥问题?是不是要使用什么convert呀,压根不认!还是我写错了?求救呀!!
action里是这样写的
class Student{
private Integer id;
private String name;
private Date birthday;
// getter and setter
}class StudentAction extends ActionSupport{ private Student stu; public String saveStudent(){
System.out.println(stu.getId());
System.out.println(stu.getName());
System.out.println(stu.getBirthday());
//some code about saving student object
}
//stu setter and setter
}struts的配置文件是这样的
<package name="student" extends="json-default">
<action name="StudentAction" class="com.StudentAction" method="saveStudent">
<result type="json">
</result>
</action>
</package>客户端的javascript是这样的
//用的是jQuery
var stu = {'id':100,'name':'张三','birthday':new Date()};
$.getJSON('StudentAction.action',{'stu':stu},function(data){
//some code
});
运行之后控制台一直报以下问题com.opensymphony.xwork2.interceptor.ParametersInterceptor - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'stu[id]' on 'class com.StudentAction: Error setting expression 'stu[id]' with value '[Ljava.lang.String;@10933e7'com.opensymphony.xwork2.interceptor.ParametersInterceptor - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'stu[name]' on 'class com.StudentAction: Error setting expression 'stu[name]' with value '[Ljava.lang.String;@1f2509c'
打印的三个属性也是null
毛哦,这是啥问题?是不是要使用什么convert呀,压根不认!还是我写错了?求救呀!!
感觉这么别扭呢,我在别处构造完整的stu对象了,
在往server提交数据前还要把属性名改下???
这。。也。