wood burning stoves 2.0*
The moose likes Servlets and the fly likes Setting cookie takes time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Setting cookie takes time?" Watch "Setting cookie takes time?" New topic
Author

Setting cookie takes time?

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
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

Joined: Oct 12, 2000
Posts: 5093
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.


42
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Yes you are right ;-) Thank you
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Setting cookie takes time?
 
Similar Threads
How to set custom HTTP REQUEST HEADER
Why session destroyed when browser closed
Access toWebsphere Portal users from ASP application?
How encrpyt all files on web server so decryptable by all users' keys?
SSO /redirect / anonymous users