Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Troubles with cookies in JSF

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Saloon Keeper
Posts: 24551
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 24551
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of userNameCookie.setDomain("/");
Try userNameCookie.setPath("/");
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same issue. Did you find any solutions ? thanks a lot ..
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Eracius",
Please check your private messages regarding an important administrative matter.
-Ben
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:



 
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic