包:com.gdxsoft.easyweb.script.display.action
类:ActionBase
方法:addCookie
删除Cookie时判断错误,如果Cookie.value == null时返回,删除Cookie时,不会进行赋值
public void addCookie(Cookie cookie) {
if (cookie == null ) {
return;
}
MStr s = new MStr();
s.a(cookie.getName());
s.a("=");
if(cookie.getValue()!=null){
s.a(cookie.getValue());
}
if (cookie.getMaxAge() > 0) {
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, cookie.getMaxAge());
String dt = c.getTime().toString();
s.a(";Expires=" + dt);
} else if (cookie.getMaxAge() < 0) {
Calendar c = Calendar.getInstance();
c.add(Calendar.YEAR, -2);
String dt = c.getTime().toString();
s.a(";Expires=" + dt);
}
if (cookie.getPath() != null && cookie.getPath().trim().length() > 0) {
s.a(";Path=" + cookie.getPath());
}
if (cookie.getSecure()) {
s.a(";Secure");
}
s.a(";HttpOnly");
this._Response.addHeader("Set-Cookie", s.toString());
}