LoginController
    /**
* 登陆方法
*/
@ResponseBody
@RequestMapping("login2")
public Map<String, String> login2(UserVo userVo, Model model) {
Map<String, String> res = new HashMap();
String code = WebUtils.getHttpSession().getAttribute("code").toString();
if(!userVo.getCode().equals(code)){
model.addAttribute("error", SysConstast.USER_LOGIN_ERROR_MSG);
res.put("code", "400");
res.put("message", "验证码错误");
return res;
}
User user = this.userService.login(userVo);
if (null == user) {
model.addAttribute("error", SysConstast.USER_LOGIN_ERROR_MSG);
res.put("code", "302");
res.put("address", "../login/toLogin.action");
return res;
}
//放到session
WebUtils.getHttpSession().setAttribute("user", user);
//记录登陆日志 向sys_login_log里面插入数据
LogInfoVo logInfoVo = new LogInfoVo();
logInfoVo.setLogintime(new Date());
logInfoVo.setLoginname(user.getRealname() + "-" + user.getLoginname());
logInfoVo.setLoginip(WebUtils.getHttpServletRequest().getRemoteAddr()); logInfoService.addLogInfo(logInfoVo);
res.put("code", "200");
res.put("address", "../login/mainIndex.action");
return res;
} @RequestMapping("mainIndex")
public String mainIndex() {
return "system/main/index";
} /**
* 得到登陆验证码
*
* @throws IOException
*/
@RequestMapping("getCode")
public void getCode(HttpServletResponse response, HttpSession session) throws IOException {
// 定义图形验证码的长和宽
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116, 36, 4, 5);
session.setAttribute("code", lineCaptcha.getCode());
ServletOutputStream outputStream = response.getOutputStream();
ImageIO.write(lineCaptcha.getImage(), "JPEG", outputStream);
}

login.jsp

    <div class="layui-form-item input-item" id="imgCode">
<label for="code">验证码</label>
<input type="text" placeholder="请输入验证码" autocomplete="off" name="code" id="code" class="layui-input">
<img src="${ctx}/login/getCode.action" onclick="this.src=this.src+'?'">
</div>

最新文章

  1. WPF 子窗体关闭时显示父窗体
  2. springMVC下集成active MQ发送邮件
  3. js鼠标滑轮滚动事件绑定(兼容主流浏览器)
  4. storm如何分配任务和负载均衡?
  5. 安卓Json介绍(转)。
  6. C#去除HTML标签(转)
  7. .Net高级技术
  8. 解决手机浏览器和微信中select中border:none;无用和去掉小三角
  9. Oracle笔记之对象权限与系统权限总结
  10. Link方式导入java项目
  11. I - Intersection HDU - 5120(圆环相交面积)
  12. [bzoj4240] 有趣的家庭菜园
  13. Spark2.4.0伪分布式环境搭建
  14. 远程连接centos7 上的mysql报(ERROR 2003 (HY000): Can&#39;t connect to MySQL server on &#39;168.x.x.x&#39; (10060) )
  15. 钉钉C# 使用数据接口要注意的问题
  16. spring+springMvc+struts的SSH框架整合
  17. vue教程2-03 vue计算属性的使用 computed
  18. activiti工作流
  19. &hellip;gen already exists but is not a source folder. Convert to a source folder or rename it [closed]
  20. Spring Boot 系统要求

热门文章

  1. 每天进步一点点------Allegro生成Gerber文件
  2. UVA 12097 Pie(二分答案)
  3. QT(mingw) 编译 boost
  4. linux nmon安装
  5. 2019 ICPC南京站网络赛 H题 Holy Grail(BF算法最短路)
  6. Yum与list结合
  7. 一些常用的js代码
  8. Multisim 中的一些快捷键
  9. opencv:全局阈值
  10. 使用IntelliJ IDEA同步Github代码