/**
??? ?* 创建cookie
??? ?*
??? ?* @param cookieName保存的cookieKey
??? ?* @param param保存的cookieValue
??? ?* @param time时效(单位:秒)
??? ?* @param response
??? ?*/
??? public static boolean addCookie(final String cookieName,
??? ??? ??? final String param, int time, HttpServletResponse response) {
??? ??? try {
??? ??? ??? // 创建保存用户的cookie
??? ??? ??? Cookie cookiesUser = new Cookie(cookieName, param);
??? ??? ??? // 设置访问域
??? ??? ??? cookiesUser.setPath("/");
??? ??? ??? // 设定自动登录期限为二周
??? ??? ??? cookiesUser.setMaxAge(time);
??? ??? ??? //
??? ??? ??? response.addCookie(cookiesUser);
??? ??? } catch (Exception e) {
??? ??? ??? e.printStackTrace();
??? ??? ??? return false;
??? ??? }
??? ??? return true;
??? }
??? /**
??? ?* 清除cookie
??? ?*
??? ?* @param cookieName要清除的cookie名
??? ?* @param response
??? ?* @return
??? ?*/
??? public static boolean deleteCookie(final String cookieName,
??? ??? ??? HttpServletResponse response) {
??? ??? try {
??? ??? ??? Cookie cookie = new Cookie(cookieName, null);
??? ??? ??? cookie.setPath("/");
??? ??? ??? // 时效为0时即时删除
??? ??? ??? cookie.setMaxAge(0);
??? ??? ??? response.addCookie(cookie);
??? ??? } catch (Exception e) {
??? ??? ??? e.printStackTrace();
??? ??? ??? return false;
??? ??? }
??? ??? return true;
??? }