在seam 中用cookies,刚开始代码可以向client写cookie。但是读的时候,一直都读不到写的cookie,看http信息头也看不到。但是在firefox中确可以看到cookie信息。
今天把cookie.setSecure(true) 给干掉了。得。 一下子全好了。NND
@In
protected javax.faces.context.FacesContext facesContext;
..
.....
private String getCookies(String name){
Cookie[] cookies = ((HttpServletRequest)facesContext.getExternalContext().getRequest()).getCookies();
if(cookies!=null){
for(int i=0;i<cookies.length;i++){
String cn = cookies[i].getName();
if(cn.equals(name)){
return cookies[i].getValue();
}
}
}
return null;
}
private void setCookie(String k,String v){
Cookie cookie = new Cookie(k, v);
cookie.setMaxAge(3600);
cookie.setVersion(32140800);
// cookie.setSecure(true);
cookie.setPath("/");
((HttpServletResponse)facesContext.getExternalContext().getResponse()).addCookie(cookie);
}
protected javax.faces.context.FacesContext facesContext;
..
.....
private String getCookies(String name){
Cookie[] cookies = ((HttpServletRequest)facesContext.getExternalContext().getRequest()).getCookies();
if(cookies!=null){
for(int i=0;i<cookies.length;i++){
String cn = cookies[i].getName();
if(cn.equals(name)){
return cookies[i].getValue();
}
}
}
return null;
}
private void setCookie(String k,String v){
Cookie cookie = new Cookie(k, v);
cookie.setMaxAge(3600);
cookie.setVersion(32140800);
// cookie.setSecure(true);
cookie.setPath("/");
((HttpServletResponse)facesContext.getExternalContext().getResponse()).addCookie(cookie);
}
Keep-Alive300
Connection
keep-alive
Cookie
JSESSIONID=1oqqa4egh88ld; star=chenglong