• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting cookie takes time?

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right ;-) Thank you
 
reply
    Bookmark Topic Watch Topic
  • New Topic