• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding a cookie

 
Chen Yanush
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I had created a login jsp file with two fields for writing your name and username, along with checkboxes for accepting a cookie placement.

I know how to create a cookie and saving the user's name in it, but I would like to plant it in the user's computer only when he clicks 'Submit' and the checkbox is checked (and not once the page comes up). How do I do that?

Moreover, how can I inform the user with a popup window that once he checks the checkbox the cookie will be placed on his computer? Do I have to do it with JavaScript or is there another way using Java?

Thanks.

Chen
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well...
the cookie aint suppose to save the name and username automatically...
it may be because of browser form history feature that the name automatically turns up when a user opens the webpage...
so when the form is syubmit you can programatically add the name and username to the cookie and use it afterwards

also, that confirmation box can be added using javascript.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to use JavaScript or some other scripting language to create the popup, since this is a client side function. Keep in mind, however, that many of the most recent browsers disable popups by default, so this may cause some problems for you.

As far as adding the cookie, when the form is submitted, have the servlet you submit it to check the boolean value of the checkbox, and if it is not checked, redirect the user to back to the login screen (usually with a message explaining why the cookie was not added). If it is checked, add the cookie.
[ December 06, 2004: Message edited by: Paul Bourdeaux ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!