Solved

Getting a Broswer Cookie from a JApplet

Posted on 2004-07-31
5
566 Views
Last Modified: 2008-01-16
Hi there, well I seem to be having some trouble retrieving a cookie from a JApplet.  The code I have works fine in an Applet, but not a JApplet.  I am just trying to get a cookie from the browser called "Session".  I was using this:

  public String getCookie()
  {
     /*
      ** get all cookies for a document
      */
     try
     {
        JSObject myBrowser = (JSObject) JSObject.getWindow(this);
        JSObject myDocument = (JSObject) myBrowser.getMember("document");
        String myCookie = (String) myDocument.getMember("cookie");
        if (myCookie.length() > 0)
           return myCookie;
     }
     catch (Exception e)
     {
        e.printStackTrace();
     }
     return "?";
  }

But the JSObject.getWindow takes in an Applet.  Any suggestions?  Thanks in advance.

Kes
0
Comment
Question by:kesea
  • 2
  • 2
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 11687037
Japplet is a subclass of Applet so that code is fine.
ie. you can pass a JApplet anywhere where an Applet is expected.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11687558
Have you tried running it with a JApplet, or are you still thinking how to do it?
0
 

Author Comment

by:kesea
ID: 11687724
I have tried it from an Applet and a JApplet, but with my JApplet I get this exception from the

JSObject myBrowser = (JSObject) JSObject.getWindow(this);  

netscape.javascript.JSException
      at netscape.javascript.JSObject.getWindow(Unknown Source.)

Can I not just pass the JApplet in using this, since it is in the scope of the JApplet?  Thanks.
0
 

Author Comment

by:kesea
ID: 11687767
Ok I figured it out.  You cannot call this function from the JInit or else it will fail.  I guess the browser hasn't loaded the JApplet fully by then.  Thanks all for the sanity check.
0
 
LVL 92

Expert Comment

by:objects
ID: 11689700
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now