Solved

Getting a Broswer Cookie from a JApplet

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

635 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