日期:2014-05-16  浏览次数:20356 次

关于用jquery传递json给struts2中的复杂对象的方法

错误信息:出现java.lang.NoSuchMethodException setUser([LJava.lang.String;)异常

struts2中的UserAction:

?1?public?class?UserAction{
?2?private?User?user;
?3?private?String?name;
?4?public?void?setName(String?name){
?5?this.name?=?name;
?6?}
?7?public?String?getName(){
?8?return?name;
?9?}
10?public?User?getUser()?{
11???????return?user;
12?}
13?
14?
15?public?void?setUser(User?user)?{
16???????this.user?=?user;
17?}
18?
19?public?String?execute(){
20??????System.println(user.getUsername);
21?}
22?
23?}
24?

User就两个属性:username/password.
这个是开始的struts.xml中的代码:

<package?name="json"?extends="json-default">