Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting a Broswer Cookie from a JApplet

Posted on 2004-07-31
5
Medium Priority
?
583 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
[X]
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
  • 2
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

715 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