• Post Reply Bookmark Topic Watch Topic
  • New Topic

Troubles with cookies in JSF

 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I've been working on a "remember my login" feature for my JSF application. My LoginBean has a method call in the constructor that does a check for cookies and logs the user in if necessary. However, I've noticed that on the first request the only cookie is the SESSIONID and not the two custom ones I've put on the machine. Is there anything special I should know in trying to get this to work?

 
Tim Holloway
Bartender
Posts: 18417
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so. But Java manages cookies quite intelligently and automatically. If you've got a lot of elaborate cookie-handling code, try simplifying it - you might be out-clevering yourself.
 
Venkat Sadasivam
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set your custom cookie path as "/" and try again.
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what I have going on:



I just added the domain code as mentioned in this thread. That didn't appear to have an effect.
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realize I had the domain stuff wrong. I changed that to path instead, still with no change.

Could this have something to do with me running in localhost? I've attempted to set the domain to http://localhost:8080 but that didn't do anything either. The only cookie that comes back in the SESSIONID.

Man, this is painful.
 
Tim Holloway
Bartender
Posts: 18417
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Locahost or localhost.localdomain are valid for cookies. Have you used your browser's cookie inspector to check and see what you've got?

I think you're aware of it, but just to say so, cookies can't be posted cross-domain for security reasons. In other words, a javaranch.com server can't create a google.com cookie.
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have looked at the cookies being set and they're there. They just don't come back from the request object on the initial load. It's very weird.
 
Venkat Sadasivam
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of userNameCookie.setDomain("/");
Try userNameCookie.setPath("/");
 
Eracius
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same issue. Did you find any solutions ? thanks a lot ..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Eracius",
Please check your private messages regarding an important administrative matter.
-Ben
 
Arragon Arragon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw you setting the maxAge to -1. This will cause deleting the cookie after the browser will be closed. So it is not any longer present for next browser session. Just for your notice.

Originally posted by Chris Stewart:



 
Mital Pritmani
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey people, I am having same issue. I don't know why these cookies are not being added though I am adding them in response object in jsf. Please do help me with my problem. I am putting some code here for reference, if anyone can look at it and help me.



Any kind of help appreciated. If there is any special param to be added anywhere, do let me know.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!