@RequestMapping("/getVcode")public void createCode(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//生成随机字串String verifyCode = VerifyCodeUtils.generateVerifyCode(4);//存入会话sessionHttpSession session = request.getSession(true);//删除以前的 session.removeAttribute("TEMP_USER_CODE"); session.setAttribute("TEMP_USER_CODE", verifyCode.toLowerCase()); String tempusercode = (String) request.getSession().getAttribute("TEMP_USER_CODE"); System.out.println("--------"+tempusercode);//生成图片int w = 150, h = 50;VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);---------------------------------------------------------------------------------------页面<form action="<%=basePath%>userManager/regedit.html" type="post"> <input type="username" name="username" placeholder="请输入用户名"><span></span><br/> <input type="password" name="password" placeholder="请输入密码"><span></span><br/> <input type="password" name="password" placeholder="再次输入密码"><span></span><br/> <div onclick="changeImg()"> <img id="img" src="<%=basePath%>getVcode" /> </div> <div > <input id="vcode" name="vcode" type="text" placeholder="输入验证码"> </div> <input type="submit" value="注册"></form>------------------------------------------------------------------------controller/*用户注册 */@RequestMapping("/regedit.html")public Map register(String username,String password,String vcode,HttpServletRequest request){ Map map = new HashMap(); boolean success = false; String tempusercode = (String) request.getSession().getAttribute("TEMP_USER_CODE"); System.out.println("验证码为"+tempusercode);========================打印出来为null?????? if(!vcode.toLowerCase().equals(tempusercode)||!vcode.toUpperCase().equals(tempusercode)){ map.put("success",success); return map; } success = userManagerService.register(username,password); map.put("success",success); return map;}
添加回答
举报
0/150
提交
取消