本人新手,也刚接触nutz,对于目的清除cookie ,和更新session,根据网上找的清除cookie,response并不起作用,这个还需要其他的条件吗?谢谢
@Inject
private NutDao dao;
@At("/login")
@Ok("json")
@Filters
public Object login(HttpServletRequest req, HttpServletResponse response, HttpSession session){
String id = session.getId();
System.out.println(id);
String username = req.getParameter("userName");
String password = req.getParameter("password");
User d = dao.fetch(User.class,Cnd.where("loginName", "=", username).and("loginPassword", "=", password));
if (d == null) {
try {
response.sendRedirect(req.getContextPath() + "/login.jsp");
} catch (IOException e) {
e.printStackTrace();
}
return ""error;
} else {
Cookie[] cookies = req.getCookies();//这样便可以获取一个cookie数组
for(Cookie cookie: cookies){
cookie.setMaxAge(0);
cookie.setValue(null);
cookie.setPath("/");
response.addCookie(cookie);
}
req.getSession().invalidate();
HttpSession session2 = req.getSession(true);
String id2 = req.getSession(true).getId();
session2.setAttribute("userInfo", d);
return "ok";
}
}
}