[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

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.

0
sujata7576
Asked:
sujata7576
  • 2
1 Solution
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now