亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

springMVC 在controller里面放在session里的值在另一個里面取不到????

springMVC 在controller里面放在session里的值在另一個里面取不到????

慕粉3674953 2017-04-25 15:38:48
@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;}
查看完整描述

3 回答

?
Poison丶刺心

TA貢獻6條經驗 獲得超0個贊

試著把session放到成員變量的位置上,再試試看

查看完整回答
反對 回復 2017-09-13
?
筱爻

TA貢獻2條經驗 獲得超0個贊

題主解決了嗎?
我也遇到同樣的問題,找了好多地方沒找到答案。
發現兩次取的session id 不一樣了,之前都好好的沒什么問題唉。

查看完整回答
反對 回復 2017-09-12
  • 3 回答
  • 0 關注
  • 4716 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號