后面修改密码再听一遍
后面不懂
点击查看代码
public void pwdModify(HttpServletRequest req, HttpServletResponse resp){
// 从session中获取用户id
Object o = req.getSession().getAttribute(Constants.USER_SESSION);
String oldpassword = req.getParameter("oldpassword");
// 万能map
HashMap<String, String> resultMap = new HashMap<String, String>();
if (o == null) {// session失效了,session过期了
resultMap.put("result", "sessionerror");
}else if (StringUtils.isNullOrEmpty(oldpassword)){//输入的密码为空
resultMap.put("result","error");
}else {
String userPassword = ((User) o).getUserPassword(); //Session中用户的密码
if (userPassword.equals(oldpassword)){
resultMap.put("result","true");
}else{
resultMap.put("result","false");
}
}
try {
resp.setContentType("application/json");
PrintWriter writer = resp.getWriter();
//JSONArray 阿里巴巴的json工具类,转换格式
/*
reusltMap = ["result",”sessionerror","result","errro"]
* JSON 格式={key : Value}
* */
writer.write(JSONArray.toJSONString(resultMap));
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}