@ResponseBody
@RequestMapping(value = "getFpassword")
public String getFpassword(@RequestBody Fpassword fpassword, BindingResult result,
ModelMap map, HttpSession session,HttpServletRequest request) throws Exception {
// 在Session里保存資訊
session.setAttribute("fpassword", fpassword);
……………………
}
session.setAttribute("fpassword", fpassword);的值

通過前臺ajax跳轉

@RequestMapping(value = "/rpassword/verify")
public String verify( Fpassword fpassword,HttpServletRequest request, HttpServletResponse response,HttpSession session,ModelMap map) {
// 在Session里獲取資訊
session.getAttribute("fpassword");
// 從服務器端的session中取出驗證碼
String user = fpassword.getUser();
System.out.println(user);
………
}
結果列印出來的user是null
uj5u.com熱心網友回復:
session.getAttribute("fpassword");改為fpassword= session.getAttribute("fpassword");試試。。。uj5u.com熱心網友回復:
1樓說的對,你只取出來了值但是卻沒有把值存到物件中去。uj5u.com熱心網友回復:
替換了還是null
uj5u.com熱心網友回復:
fpassword 是一個物件?難道不要強轉下?uj5u.com熱心網友回復:
代碼怎么寫的???
uj5u.com熱心網友回復:
session.getAttribute("fpassword");改為fpassword= session.getAttribute("fpassword");試試。。。
替換了還是null
代碼怎么寫的???
@RequestMapping(value = "/rpassword/verify")
public String verify( Fpassword fpassword,HttpServletRequest request, HttpServletResponse response,HttpSession session,ModelMap map) {
// 在Session里獲取資訊
fpassword= (Fpassword) session.getAttribute("fpassword");
// 從服務器端的session中取出驗證碼
String user = fpassword.getUser();
map.addAttribute("user", user);
System.out.println("Session手機號碼"+user);
return "/WEB-INF/jsp/safetyVerify.jsp";
}
uj5u.com熱心網友回復:
session.getAttribute("fpassword");改為fpassword= session.getAttribute("fpassword");試試。。。
替換了還是null
代碼怎么寫的???
@RequestMapping(value = "/rpassword/verify")
public String verify( Fpassword fpassword,HttpServletRequest request, HttpServletResponse response,HttpSession session,ModelMap map) {
// 在Session里獲取資訊
fpassword= (Fpassword) session.getAttribute("fpassword");
// 從服務器端的session中取出驗證碼
String user = fpassword.getUser();
map.addAttribute("user", user);
System.out.println("Session手機號碼"+user);
return "/WEB-INF/jsp/safetyVerify.jsp";
}
你列印一下System.out.println(fpassword==null);
uj5u.com熱心網友回復:
session.getAttribute("fpassword");改為fpassword= session.getAttribute("fpassword");試試。。。
替換了還是null
代碼怎么寫的???
@RequestMapping(value = "/rpassword/verify")
public String verify( Fpassword fpassword,HttpServletRequest request, HttpServletResponse response,HttpSession session,ModelMap map) {
// 在Session里獲取資訊
fpassword= (Fpassword) session.getAttribute("fpassword");
// 從服務器端的session中取出驗證碼
String user = fpassword.getUser();
map.addAttribute("user", user);
System.out.println("Session手機號碼"+user);
return "/WEB-INF/jsp/safetyVerify.jsp";
}
你列印一下System.out.println(fpassword==null);
列印出來的是false
uj5u.com熱心網友回復:
session.getAttribute("fpassword");改為fpassword= session.getAttribute("fpassword");試試。。。
替換了還是null
代碼怎么寫的???
@RequestMapping(value = "/rpassword/verify")
public String verify( Fpassword fpassword,HttpServletRequest request, HttpServletResponse response,HttpSession session,ModelMap map) {
// 在Session里獲取資訊
fpassword= (Fpassword) session.getAttribute("fpassword");
// 從服務器端的session中取出驗證碼
String user = fpassword.getUser();
map.addAttribute("user", user);
System.out.println("Session手機號碼"+user);
return "/WEB-INF/jsp/safetyVerify.jsp";
}
你列印一下System.out.println(fpassword==null);
列印出來的是false
fpassword里的key值列印出來都是null
uj5u.com熱心網友回復:
session.getAttribute("fpassword");改為fpassword= session.getAttribute("fpassword");試試。。。
替換了還是null
代碼怎么寫的???
@RequestMapping(value = "/rpassword/verify")
public String verify( Fpassword fpassword,HttpServletRequest request, HttpServletResponse response,HttpSession session,ModelMap map) {
// 在Session里獲取資訊
fpassword= (Fpassword) session.getAttribute("fpassword");
// 從服務器端的session中取出驗證碼
String user = fpassword.getUser();
map.addAttribute("user", user);
System.out.println("Session手機號碼"+user);
return "/WEB-INF/jsp/safetyVerify.jsp";
}
你列印一下System.out.println(fpassword==null);
列印出來的是false
fpassword里的key值列印出來都是null
那和session沒什么關系了,是你接受資料的問題。。。
你的資料json_str設定為{"key":"value"}這種格式的,把@RequestBody去掉,試試。。。。
uj5u.com熱心網友回復:
你的user應該不是String型別吧,User user = ..uj5u.com熱心網友回復:
你的user應該不是String型別吧,User user = ..
user里有很多KEY,我輸出的并不是User,輸出值是String沒錯
uj5u.com熱心網友回復:
session.getAttribute("fpassword");改為fpassword= session.getAttribute("fpassword");試試。。。
替換了還是null
代碼怎么寫的???
@RequestMapping(value = "/rpassword/verify")
public String verify( Fpassword fpassword,HttpServletRequest request, HttpServletResponse response,HttpSession session,ModelMap map) {
// 在Session里獲取資訊
fpassword= (Fpassword) session.getAttribute("fpassword");
// 從服務器端的session中取出驗證碼
String user = fpassword.getUser();
map.addAttribute("user", user);
System.out.println("Session手機號碼"+user);
return "/WEB-INF/jsp/safetyVerify.jsp";
}
你列印一下System.out.println(fpassword==null);
列印出來的是false
fpassword里的key值列印出來都是null
那和session沒什么關系了,是你接受資料的問題。。。
你的資料json_str設定為{"key":"value"}這種格式的,把@RequestBody去掉,試試。。。。
不能去掉@RequestBody ,他是接受前臺傳過來json字串的。前臺傳給后臺的就是你這格式啊
uj5u.com熱心網友回復:
應該是@ResponseBody,加到requestMapper下面試試。uj5u.com熱心網友回復:
建議用request獲取session。uj5u.com熱心網友回復:
存全域session資訊建議用request.getSession().settAttribute();同樣后臺取也是如此。。 資料controller 資料建議通過model 來add
uj5u.com熱心網友回復:
檢查一下代碼有沒有錯誤,然后就是谷歌瀏覽器的問題了,跨controller取值為null的問題浪費我半小時.檢查谷歌瀏覽器有沒有顯示鏈接不安全轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/141041.html
標籤:Java EE
上一篇:求助,springboot+mybatis,用@Select查詢回傳null
下一篇:Java背景圖片
