今天写的一些代码,之前个人中心没写完,发到博客上,估计开发系统会经常用到
/**
* 显示用户的个人中心
* @param request
* @param response
* @throws ServletException
* @throws IOException
* @author Harry
*/
private void showPersonal(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
//找到保存到session中的登录用户
SimsSystemUser user = (SimsSystemUser) request.getSession().getAttribute("user");
//通过用户id重新查找用户
SimsSystemUser userNow = userService.findUserById(user.getUserId());
//加载用户所属部门和角色,解决懒加载的问题
Hibernate.initialize(userNow.getDepartment());
Hibernate.initialize(userNow.getSystemRole());
//保存到request中,转发显示
request.setAttribute("userNow", userNow);
request.getRequestDispatcher("/jsps/user/personal.jsp").forward(request, response);//显示当前用户的个人信息
}
/**
* 跳转到修改信息界面
* @param request
* @param response
* @throws ServletException
* @throws IOExeption
* @author Harry
*/
private void forUpdatePersonal(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
//找到保存到session中的登录用户
SimsSystemUser user = (SimsSystemUser) request.getSession().getAttribute("user");
//通过用户id重新查找用户
SimsSystemUser userNow = userService.findUserById(user.getUserId());
//加载用户所属部门和角色,解决懒加载的问题
Hibernate.initialize(userNow.getDepartment());
Hibernate.initialize(userNow.getSystemRole());
//保存到request中,转发显示
request.setAttribute("userNow", userNow);
request.getRequestDispatcher("/jsps/user/forchangepersonal.jsp").forward(request, response);
}
/**
* 修改用户个人信息
* @param request
* @param response
* @throws ServletException
* @throws IOException
* @author Harry
*/
private void updatePersonal(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
SimsSystemUser user = (SimsSystemUser) request.getSession().getAttribute("user");
//通过用户id重新查找用户
SimsSystemUser userNow = userService.findUserById(user.getUserId());
//加载用户所属部门和角色,解决懒加载的问题
Hibernate.initialize(userNow.getDepartment());
Hibernate.initialize(userNow.getSystemRole());
//suPhone userSex suIdentityCard
String phone = request.getParameter("suPhone");
String sex = request.getParameter("userSex");
String suIdentityCard = request.getParameter("suIdentityCard");
System.out.println("手机号:"+phone+"性别:"+sex+"ID卡:"+suIdentityCard);
//进行修改
userNow.setSuPhone(phone);
userNow.setSuSex(sex);
userNow.setSuIdentityCard(suIdentityCard);
//保存到request中,转发显示
request.setAttribute("userNow", userNow);
request.getRequestDispatcher("/jsps/user/personal.jsp").forward(request, response);
}
/**
* 用户修改密码
* @param request
* @param response
* @throws IOException
* @throws ServletException
* @author Harry
*/
private void changePassword(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException{
System.out.println("执行到了changePassword函数");
PrintWriter pw = response.getWriter();
//找到保存到session中的登录用户