@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
提交
取消