public void update() throws IOException {
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
try {
JSONArray array = JSONArray.fromObject(data);
System.out.println(data);
Object[] objs = array.toArray();
for (Object object : objs) {
JSONObject obj = (JSONObject) object;
if (null != obj && !"".equals(obj.getString("id"))) {
User userUpdate = new User();
user = userDao.findUserById(obj.getString("id"));
userUpdate.setUserAccount(obj.getString("userAccount"));
userUpdate.setUserId(obj.getString("id"));
userUpdate.setUserName(obj.getString("realName"));
userUpdate.setAddress(obj.getString("address"));
userUpdate.setUserDuty(obj.getString("userDuty"));
userUpdate.setEnabled(true);
userUpdate.setIssys(false);
userUpdate.setSex(obj.getString("sex"));
userDao.updateUser(userUpdate);
}
}
response.getWriter().print("保存成功");
} catch (Exception e) {
e.printStackTrace();
response.getWriter().print("保存失败");
}
}
SSH,这段代码是从客户端接收DATA JSON数据
更新
User
java.lang.NullPointerException
at com.action.UserAction.update(UserAction.java:170)
就是这一行userUpdate.setUserAccount(obj.getString("userAccount"));
输出是有值的,让我感到很郁闷
------解决方案--------------------
.......