Solved

Getting a Broswer Cookie from a JApplet

Posted on 2004-07-31
5
569 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 84
mockito example issue 8 72
Basic Java Case or If-Else statement... 3 50
null output 3 25
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

770 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