JavaWeb个人信息修改及修改密码

这篇博客分享了如何在JavaWeb应用中实现个人信息修改和密码更改的功能,包括personal.jsp页面的相关代码和实现过程,适合开发者参考。
摘要由CSDN通过智能技术生成

今天写的一些代码,之前个人中心没写完,发到博客上,估计开发系统会经常用到


/**
	 * 显示用户的个人中心 
	 * @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中的登录用户
	
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值