Skip to content

Commit

Permalink
CookieUtils.getCookie增加path参数
Browse files Browse the repository at this point in the history
  • Loading branch information
think-gem committed Mar 30, 2018
1 parent 198844b commit 2f45433
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions common/src/main/java/com/jeesite/common/web/CookieUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ public static void setCookie(HttpServletResponse response, String name, String v
public static String getCookie(HttpServletRequest request, String name) {
return getCookie(request, null, name, false);
}

/**
* 获得指定Cookie的值,并删除。
* @param name 名称
* @return 值
*/
public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name) {
return getCookie(request, response, name, true);
return getCookie(request, response, name, false);
}

/**
* 获得指定Cookie的值
* @param request 请求对象
Expand All @@ -97,6 +99,18 @@ public static String getCookie(HttpServletRequest request, HttpServletResponse r
* @return 值
*/
public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name, boolean isRemove) {
return getCookie(request, response, name, "/", false);
}

/**
* 获得指定Cookie的值
* @param request 请求对象
* @param response 响应对象
* @param name 名字
* @param isRemove 是否移除
* @return 值
*/
public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name, String path, boolean isRemove) {
String value = null;
if (StringUtils.isNotBlank(name)){
Cookie[] cookies = request.getCookies();
Expand All @@ -108,7 +122,8 @@ public static String getCookie(HttpServletRequest request, HttpServletResponse r
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (isRemove) {
if (isRemove && response != null) {
cookie.setPath(path);
cookie.setMaxAge(0);
response.addCookie(cookie);
}
Expand Down

0 comments on commit 2f45433

Please sign in to comment.