Struts has detected an unhandled exception:
Messages: |
|
该类中UserManager不需要添加到json中,但是被添加了,造成了异常,解决方法,在getXXX()上面添加@JSON(serialize=false)
public class JsonAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -9040282050464969108L;
private String isSuccess = "success";
private List<Map<String, Object>> users = new ArrayList<Map<String, Object>>();
private UserManager userManager;
@JSON(name="result")
public String getIsSuccess() {
return isSuccess;
}
public void setIsSuccess(String isSuccess) {
this.isSuccess = isSuccess;
}
public List<Map<String, Object>> getUsers() {
return users;
}
public void setUsers(List<Map<String, Object>> users) {
this.users = users;
}
<span style="white-space:pre">@JSON(serialize=false)</span>public UserManager getUserManager() {return userManager;}public void setUserManager(UserManager userManager) {this.userManager = userManager;}@Overridepublic String execute() throws Exception {List<User> userList = userManager.listUsers();for(User user : userList){Map<String, Object> jsonMap = new HashMap<String, Object>();jsonMap.put("id", user.getId());jsonMap.put("username", user.getUsername());jsonMap.put("password", user.getPassword());users.add(jsonMap);}return SUCCESS;}}