/** * 方法<code>setState</code> 设置登录状态 * * @param id * @param state * @return boolean */ public boolean setState(String id, Boolean state) { /** 通过专家id查询专家对象* */ ExpeRegi expe = getExpeinfoById(id); if (expe == null) return false; /** 如果专家对象非空则设置专家状态* */ Session session = HibernateSessionFactory.getSession(); org.hibernate.Transaction tx = session.beginTransaction(); expe.setState(state); session.update(expe); tx.commit(); // 提交事务。 session.close(); return true; }
// 实现退出当前帐号 public String Logout() { System.out.println("LogoutAction---Logout()"); // 获取request对象和response对象 HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); ApplicationContext otx = new ClassPathXmlApplicationContext("applicationContext.xml"); // Spring调用相应DAO MembRegiDAO mDao = (MembRegiDAO) otx.getBean("MembRegiDAO"); // Spring调用相应DAO ExpeRegiDAO eDao = (ExpeRegiDAO) otx.getBean("ExpeRegiDAO"); // 获取session对象 Map<String, Object> session = ServletActionContext.getContext().getSession(); String forward = "error"; System.out.println("forward---"); String name = ""; try { request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); name = request.getParameter("name"); System.out.println("会员编号:" + name); } catch (UnsupportedEncodingException e) { System.out.println("会员编号:" + 4444); e.printStackTrace(); } System.out.println("专家编号:" + name); ExpeRegi expert = eDao.getExpeinfoById(name); // 调用getMembinfoById方法,通过id查看用户注册信息 MembRegi member = mDao.getMembinfoById(name); if (expert != null) { System.out.println("专家--" + expert.getExpeId() + "退出"); expert.setState(false); eDao.UpdateExpeRegi(expert); session.clear(); forward = "success"; } else if (member != null) { System.out.println("会员--" + member.getMembId() + "退出"); member.setState(false); mDao.UpdateMembRegi(member); session.clear(); forward = "success"; } else { forward = "error"; } return forward; }
/** * 方法<code>checkLogin</code> 专家登录检查,合法返回true,否则返回false * * @param username * @param password * @return boolean */ public int checkLogin(String username, String password) { System.out.println("进入ExpeRegiDAO--checkLogin()--登录检查:0正确,1用户名为空,2其他错误"); ExpeRegi expe = getExpeinfoById(username); System.out.println("专家名:" + username); System.out.println("密 码:" + password); if (expe == null) { return 1; } else { if (expe.getExpePass().equals(password)) { System.out.println("success:" + expe.getExpePass()); expe.setState(Boolean.TRUE); UpdateExpeRegi(expe); return 0; } else { return 2; } } }