cookie作用域修改

This commit is contained in:
keyuan 2021-04-15 15:55:56 +08:00
parent d1648b56b9
commit f6e06632a8
2 changed files with 5 additions and 25 deletions

View File

@ -7,7 +7,7 @@ import javax.servlet.http.HttpServletResponse;
public class CookieUtils {
/**
* 添加cookie
*
*
* @param response
* @param name
* Cookie的名称不能为null
@ -34,27 +34,6 @@ public class CookieUtils {
response.addCookie(cookie);
}
/**
* 设置cookie
*
* @param response
* @param name
* cookie名字
* @param value
* cookie值
* @param maxAge
* cookie生命周期 以秒为单位
*/
public static void addCookie(HttpServletResponse response, String name,
String value, int maxAge) {
Cookie cookie = new Cookie(name, value);
cookie.setPath("/");
if (maxAge > 0)
cookie.setMaxAge(maxAge);
response.addCookie(cookie);
}
/**
* @param request

View File

@ -197,8 +197,9 @@ public class DwsAnswerAction extends ActionSupport {
entity.setDataSource(0);
surveyAnswerManager.saveAnswer(entity, quMaps);
int effe = surveyDetail.getEffectiveTime();
CookieUtils.addCookie(response, surveyId, (ipNum + 1) + "",
effe * 60, "/");
effe * 60, request.getContextPath());
} catch (Exception e) {
e.printStackTrace();
return RELOAD_ANSWER_FAILURE;
@ -248,7 +249,7 @@ public class DwsAnswerAction extends ActionSupport {
int effe = surveyDetail.getEffectiveTime();
CookieUtils.addCookie(response, surveyId, (ipNum + 1) + "",
effe * 60, "/");
effe * 60, request.getContextPath());
} catch (Exception e) {
e.printStackTrace();
return RELOAD_ANSWER_FAILURE;
@ -465,4 +466,4 @@ public class DwsAnswerAction extends ActionSupport {
this.surveyId = surveyId;
}
}
}