Solved

Printing in IE4 and Netscape4

Posted on 1998-05-04
2
146 Views
Last Modified: 2010-04-16
Netscape defines a set of classes to grant applets permissions to do specific things.  I use the PrivilegeManager.enablePrivilege method to request permissions for my signed applet.  Including these calls in my code causes IE4 to toss exceptions because it can't find the Netscape classes.  Java doesn't give me conditional complitation, and I don't want to maintain 2 sets of sources, one for each browser.

BTW, the Capablities API works fine with Netscape 4.05.

I can detect which browser my applet is running under.

Is there any way to use the Netscape classes from code that can be run without exceptions under IE4?
0
Comment
Question by:gerry99
2 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 50 total points
ID: 1220527
There is no conditional compilation but you have dynamic object instantiation through

Class.forName("myPackage.myClass").newInstance();

Put all the logic to request a privilege in a constractor of some class and look for  InstantiationException. If you are running in Netscape, the class will be instantiated and code to request privilege executed.  If the exception gets thrown which means the class could not be instantiated (e.g it could not find Netscape's classes), then simply continue processing.

Hope that helps.
0
 
LVL 1

Author Comment

by:gerry99
ID: 1220528
This answer works, and it deserves to be called the "hack of all ages".  I'm not sure how the language specification should be changed, but as long as applets must make use of libraries that exist in some browsers, but not in others, some form of conditional compilation is required.  Notice that with this technique *all* the work must be done in a constructor, because if you wanted to call a method on this class, it would have to be loaded and verified on both platforms and would toss exceptions on the one that does not contain some of the classes that it uses.

Thanks,
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Server Faces parameter pass? 6 48
how do i compare an object based on two fields 6 53
servlet example 11 40
how to see all occupied ports on windows 10 laptop 15 65
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)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

776 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