我退出時訪問exit能洗掉資料但是顯示302,用戶資料還在,要重繪一下頁面資料就沒了,怎么解決這種問題???
public void exit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//銷毀資料
// request.getSession().invalidate();
//獲取所有Cookie
Cookie[] cookies = request.getCookies();
//清除所有Cookie
for (Cookie c:cookies){
c.setValue(null);
c.setMaxAge(0);
System.out.println(c.getValue());
}
//重定向轉到登錄頁面
response.sendRedirect(request.getContextPath() + "/login.html");
}
public void findOne(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//獲取所有Cookie
Cookie[] cookies = request.getCookies();
//排除自帶的Cookie
for (Cookie c:cookies){
if (c.getName().equalsIgnoreCase("JSESSIONID")){
c.setMaxAge(0);
c.setValue(null);
}
}
if (cookies[0].getName() != null && cookies[0].getValue() != null) {
String name = cookies[0].getValue();
User user = new User();
user.setName(name);
//回傳資料給客戶端
writeValue(user, response);
} else {
writeValue(null, response);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/30427.html
標籤:HTML5
