[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


write cookie fro applet

Posted on 2004-10-29
Medium Priority
Last Modified: 2013-11-24
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.

Question by:sujata7576
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 92

Expert Comment

ID: 12441928
the session id is probably already being written to a cookie.

Author Comment

ID: 12443164

<< 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
LVL 92

Expert Comment

ID: 12449523

o/wise using jsobject:

JSObject document = (JSObject) JSObject.getWindow(this).getMember("document");      

Accepted Solution

lcwiding earned 150 total points
ID: 12450144
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);
      document.cookie = cookieName + "=" + escape(sessionID);


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.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question