Re: Problem with cookies
Hi DavidThanks for your help.First the ladeCookie() was just for testing and not part of my Solution. After your mail I checked my code again and checked if the cookie is really saved. In Firefox I could see my cookie but my ladeCookie() function could not read it. So I checked all attributes of the cookie and found the path attribute. Here I could see that through a wrong path my code was not able to read it. I changed the path and now it works. thanksHans2006/1/23, David G. Friedman <[EMAIL PROTECTED]>: Hans, Adding a cookie to the Response object does not automatically add it to the Request object. You have to wait until your page finishes so the client can receive the cookie. Requests AFTER that will have the cookie. In your code, I see you setting a cookie in speichereCookies() but immediately checking for it in the Request object by invoking ladeCookie() at the end of that method. The problem is you just created the cookie in the HttpServletResponse and the client didn't get it yet. Remember the Request and Response objects are not tied together. Again, the NEXT client submit should have your cookie set and readable in the Request object. Regards, David Friedman / [EMAIL PROTECTED] -Original Message-From: Hans Sowa [mailto:[EMAIL PROTECTED]]Sent: Monday, January 23, 2006 5:49 AMTo: MyFaces DiscussionSubject: Re: Problem with cookies Hi allCan somebody help me?Thanks in advance. 2006/1/20, Hans Sowa <[EMAIL PROTECTED]>: HiI try to save and load cookies from my Myfaces projekt. I see that I save the cookies in the response but if I load the cookies again I can just find the myfaces cookies but not my ones.Here is the code which I use: load code: public void ladeCookie() { Cookie[] cookies; FacesContext faces = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) faces .getExternalContext().getRequest(); cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals(SessionUser.DATENBANK)) { this.setDatenBank(cookies[i].getValue()); } } }save code: public void speichereCookies() { Cookie c = new Cookie(SessionUser.DATENBANK, this.getDatenBank()); c.setMaxAge(-1); FacesContext faces = FacesContext.getCurrentInstance (); HttpServletResponse response = (HttpServletResponse) faces .getExternalContext().getResponse(); response.addCookie(c); this.ladeCookie(); }Hope this is enough to find the problem.Thanks in advance. -- mfg Hans Sowamailto:[EMAIL PROTECTED]
RE: Problem with cookies
Hans, Adding a cookie to the Response object does not automatically add it to the Request object. You have to wait until your page finishes so the client can receive the cookie. Requests AFTER that will have the cookie. In your code, I see you setting a cookie in speichereCookies() but immediately checking for it in the Request object by invoking ladeCookie() at the end of that method. The problem is you just created the cookie in the HttpServletResponse and the client didn't get it yet. Remember the Request and Response objects are not tied together. Again, the NEXT client submit should have your cookie set and readable in the Request object. Regards, David Friedman / [EMAIL PROTECTED] -Original Message-From: Hans Sowa [mailto:[EMAIL PROTECTED]Sent: Monday, January 23, 2006 5:49 AMTo: MyFaces DiscussionSubject: Re: Problem with cookies Hi allCan somebody help me?Thanks in advance. 2006/1/20, Hans Sowa <[EMAIL PROTECTED]>: HiI try to save and load cookies from my Myfaces projekt. I see that I save the cookies in the response but if I load the cookies again I can just find the myfaces cookies but not my ones.Here is the code which I use: load code: public void ladeCookie() { Cookie[] cookies; FacesContext faces = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) faces .getExternalContext().getRequest(); cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals(SessionUser.DATENBANK)) { this.setDatenBank(cookies[i].getValue()); } } }save code: public void speichereCookies() { Cookie c = new Cookie(SessionUser.DATENBANK, this.getDatenBank()); c.setMaxAge(-1); FacesContext faces = FacesContext.getCurrentInstance (); HttpServletResponse response = (HttpServletResponse) faces .getExternalContext().getResponse(); response.addCookie(c); this.ladeCookie(); }Hope this is enough to find the problem.Thanks in advance.
Re: Problem with cookies
Hi allCan somebody help me?Thanks in advance.2006/1/20, Hans Sowa <[EMAIL PROTECTED]>: HiI try to save and load cookies from my Myfaces projekt. I see that I save the cookies in the response but if I load the cookies again I can just find the myfaces cookies but not my ones.Here is the code which I use: load code: public void ladeCookie() { Cookie[] cookies; FacesContext faces = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) faces .getExternalContext().getRequest(); cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals(SessionUser.DATENBANK)) { this.setDatenBank(cookies[i].getValue()); } } } save code: public void speichereCookies() { Cookie c = new Cookie(SessionUser.DATENBANK, this.getDatenBank()); c.setMaxAge(-1); FacesContext faces = FacesContext.getCurrentInstance (); HttpServletResponse response = (HttpServletResponse) faces .getExternalContext().getResponse(); response.addCookie(c); this.ladeCookie(); } Hope this is enough to find the problem.Thanks in advance.-- mfg Hans Sowamailto: [EMAIL PROTECTED] -- mfg Hans Sowamailto:[EMAIL PROTECTED]