【SaaS - Export项目】用户登录,显示,退出 删除session中的用户信息 销毁session
生活随笔
收集整理的這篇文章主要介紹了
【SaaS - Export项目】用户登录,显示,退出 删除session中的用户信息 销毁session
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
用戶(hù)登錄,顯示,退出
- 登錄
- 登錄分析
- TestUserService
- UserServiceImpl
- IUserDao
- IUserDao.xml
- UserController
- jsp修改步驟
- 退出
- 分析
- 步驟:刪除session登錄數(shù)據(jù) 銷(xiāo)毀session
- UserController
- header.jsp
- BaseController獲取企業(yè)
登錄
登錄分析
提交賬號(hào)密碼到后臺(tái)驗(yàn)證
》成功,進(jìn)入主頁(yè)
》失敗,提示用戶(hù)
TestUserService
@Testpublic void test06(){//根據(jù) email查詢(xún)對(duì)應(yīng)的用戶(hù)String email = "lw@export.com";String password="123";User user = iUserService.findUserByEmail(email);l.info("test06 user "+user);if (user != null) {//1:找到//比較賬號(hào)密碼if(user.getPassword().equals(password)){//正確l.info("正確");}else{//密碼不對(duì)l.info("密碼不對(duì)");}}else{//2:沒(méi)找到//用戶(hù)不存在l.info("用戶(hù)不存在");}}UserServiceImpl
User findUserByEmail(String email);@Overridepublic User findUserByEmail(String email) {return iUserDao.finByEmail(email);}IUserDao
User finByEmail(String email);IUserDao.xml
<select id="finByEmail" parameterType="string" resultMap="userMap">select * from pe_user where email=#{email};</select>UserController
//${path}/system/user/login.do//email//password@RequestMapping(path = "/login", method = {RequestMethod.GET, RequestMethod.POST})public String login(String email,String password){//根據(jù) email查詢(xún)對(duì)應(yīng)的用戶(hù)l.info("login email "+email);l.info("login password "+password);User user = iUserService.findUserByEmail(email);l.info("login user "+user);if (user != null) {//1:找到//比較賬號(hào)密碼if(user.getPassword().equals(password)){//正確l.info("正確");//保存用戶(hù)信息session.setAttribute("loginUser",user);//跳到主頁(yè)return "redirect:/home/toMain.do";}else{//密碼不對(duì)l.info("密碼不對(duì)");request.setAttribute("error","郵箱或者密碼不對(duì)");return "forward:/login.jsp";}}else{//2:沒(méi)找到//用戶(hù)不存在l.info("用戶(hù)不存在");request.setAttribute("error","用戶(hù)不存在");return "forward:/login.jsp";}}jsp修改步驟
1.找登錄表單,修改表單 提交的地址
2.查看參數(shù)名稱(chēng)是否正確
3.點(diǎn)擊提交
4.顯示來(lái)自request的提示信息
退出
分析
刪除 session中的用戶(hù)數(shù)據(jù)
步驟:刪除session登錄數(shù)據(jù) 銷(xiāo)毀session
刪除session登錄數(shù)據(jù) session.removeAttribute(“l(fā)oginUser”);
銷(xiāo)毀session session.invalidate();
UserController
@RequestMapping(path = "/loginOut", method = {RequestMethod.GET, RequestMethod.POST})public String loginOut(){//刪除session中的用戶(hù)信息session.removeAttribute("loginUser");//讓session過(guò)期session.invalidate();return "redirect:/login.jsp";//轉(zhuǎn)發(fā)不會(huì)改地址的數(shù)據(jù),只有重定向會(huì)}header.jsp
注銷(xiāo)
BaseController獲取企業(yè)
BaseController
//定義一個(gè)可以返回companyIdpublic String getLoginCompanyId(){User user = (User) session.getAttribute("loginUser");if (user != null) {return user.getCompanyId();} else {return "1";}}//定義一個(gè)可以返回companyNamepublic String getLoginCompanyName(){User user = (User) session.getAttribute("loginUser");if (user != null) {return user.getCompanyName();} else {return "吉首大學(xué)";}}總結(jié)
以上是生活随笔為你收集整理的【SaaS - Export项目】用户登录,显示,退出 删除session中的用户信息 销毁session的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 《漫步华尔街》摘抄与读后感
- 下一篇: 细胞识别图像处理项目总结