write cookie fro applet

hi all,

I am using applet-servlet communication to write data onto client machine when user logs in for the first time.  I want to save my sessionID in a cookie . how do i do it from my applet??
PS:  I do not want to use netscape.javascript package since i dont have a control over browser version/ type  and OS of client machine.

sujata7576Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
the session id is probably already being written to a cookie.
0
sujata7576Author Commented:

<< the session id is probably already being written to a cookie. >>

No, Actually the session we are  maintaining is not Tomcat Session ,but some customized Session which is created when user logs in and expires on log out . so this sessionid is not written in cookie
0
objectsCommented:
http://www.jguru.com/faq/view.jsp?EID=112568

o/wise using jsobject:

JSObject document = (JSObject) JSObject.getWindow(this).getMember("document");      
document.setMember("cookie","User=neurofase");
0
lcwidingCommented:
If you do not want to use JSObject, which is supported in most browsers and JREs, and I can understand this, then my recommendation would be to turn the issue around, and use JavaScript to write the cookie.

Depending on when your applet determines what the session ID will be, you can have your JavaScript poll the applet. SOmeting along the lines of:

<body onLoad="poll()">

<applet name=MyApplet ....>

<script language="javascript">
function poll()
{
   var sessionID = MyApplet.getSessionID();
   if (sessionID == null)
   {
      setTimeout("poll();", 1000);
   }
   else
   {
      document.cookie = cookieName + "=" + escape(sessionID);
   }
}

</script>

This is the simplest form, and once the cookie has been set, you can stop the polling.

You can also add expiration and domain settings as well if you wish.

As for using this, one reason I can see is that I have encountered browser/JRE combinations where, either JSObject does not exist, or the Java to JavaScript simply does not work. Also, the latest Sun JREs (1.4.2_05 and 1.5) have acknowledged bugs in this communication that have the potential to lock up the browser. I do not believe those woudl come into play in your case, but they are another reason to avoid the mechanism.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.