As Bear has stated, containers have server-side functionality implemented that can manage much of this for you, we do not recommend doing it in JavaScript on the client.
If you want to look at the container managed authentication, have a look at FORM based authentication, available in any good
J2EE servlet container. If you would still like to do it using JavaScript you can ask a question in the HTML/JS forum or we can move the
thread there for you.
Dave