This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting cookie takes time?

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my login servlet I make a test if it is possible to set add a cookie on the users computer. Only if it is possible to add the cookie the user is allowed to login the system.
If I have turned on the cookie settings on my computer and I try to login, the I a�m rejected first time but second time I can login the system.
I use this code to test if the users computer has enabled cookie settings.
cookie = new Cookie("test" , "test" );
cookie.setMaxAge( 100 );
cookie.setPath ("/");
response.addCookie( cookie );

for ( int i = 0 ; i < cookies.length ; i++ ){

cookie = cookies[ i ];
c_name = cookie.getName();
if ( c_name.equals( sheme_test ) ) {
cookieSettings = true;
}
}

if ( cookieSettings ){
//LOGIN
}
else {
//LOGOUT
}
It seems that the problem is that the the program is to slowly with ading the cookie and because of that it can�t find the cookie first time but only second time.
What is the problem and how can I solve it?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your understanding of the entire mechanism seems flawed.
A cookie is NOT set on the client the instant you set it in your servlet code.
The actual cookie is only set when the servlet returns to the client the result of the request.
You should not test if the cookie can be written during login, it's pointless.
If the client doesn't let the cookie be written that's its problem, not yours.
They'll just fail to give back the cookie content during the next request at which point you can tell them what's going on.
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right ;-) Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic