HTML code for Java applets that fails gracefully?

M

Mickey Segal

What is the best HTML code to add to simple applet tag code so that it fails
gracefully if Java is not working?

These days there are so many ways to have Java not work, involving different
Java VMs and settings in different browsers to turn off Java. What is the
best way now to modify the applet tag code so the user is told that Java is
not working?

The type of HTML code I'd like to add to is of the form:
<applet code="java_working.class" WIDTH="100" HEIGHT="100"></applet>
 
M

Michael Borgwardt

Mickey said:
What is the best HTML code to add to simple applet tag code so that it fails
gracefully if Java is not working?

These days there are so many ways to have Java not work, involving different
Java VMs and settings in different browsers to turn off Java. What is the
best way now to modify the applet tag code so the user is told that Java is
not working?

The type of HTML code I'd like to add to is of the form:
<applet code="java_working.class" WIDTH="100" HEIGHT="100"></applet>

A basic property of HTML is that browsers must ignore tags they don't know
or can't process but still display the text between the tags. The <applet>
was intentionally designed to make use of this for downward compatibility:
If the browser can display the applet, it will ignore everything btweenn
the applet start and end tags, otherwise it will be displayed.
 
A

Andrew Thompson

What is the best HTML code to add to simple applet tag code so that it fails
gracefully if Java is not working?

After much research, I believe the
tags (html applet attributes) and
strategy I use here is the best.
http://www.physci.org/codes/jre.jsp

This page, for example, redirects the
user who is using a JVM less than v 1.4
http://www.physci.org/codes/jretest.jsp?v=14

You can also see it in action in the
applets that I show on the main PhySci site.

Note also that it helps to have HTML
(and styles) that are validated by
the relevant standard validator.

HTH
 
F

Filip Larsen

Mickey Segal
What is the best HTML code to add to simple applet tag code so that it fails
gracefully if Java is not working?

If you are thinking about feedback to the user when the applet do not
load, you should be able to do that with JavaScript by checking if the
applet class is undefined.


Regards,
 
J

Jon A. Cruz

Mickey said:
These days there are so many ways to have Java not work, involving different
Java VMs and settings in different browsers to turn off Java. What is the
best way now to modify the applet tag code so the user is told that Java is
not working?

Just remember...

It may not be that it's not working, it may be that it's been
intentionally turned off by the user. Support that in your HTML.
 
M

Mickey Segal

Michael Borgwardt said:
A basic property of HTML is that browsers must ignore tags they don't know
or can't process but still display the text between the tags. The <applet>
was intentionally designed to make use of this for downward compatibility:
If the browser can display the applet, it will ignore everything btweenn
the applet start and end tags, otherwise it will be displayed.

Using the test applet and HTML code as on http://segal.org/java/Hello2/, if
I disable Java within Internet Explorer on Windows, the words "Java does not
work" within the applet tags gets displayed as intended (regardless of
whether the Sun or Microsoft JVM is used). However, if I disable Java
within Netscape for Windows, the error message does not appear.

The HTML I am using is:
<APPLET code="Hello.class" WIDTH=130 HEIGHT=40> Java does not work </APPLET>

I was expecting the Netscape and Sun combination to adhere most closely to
the standards.

Is there a good approach using applet tags that works on a wide variety of
software combinations?
 
A

Andrew Thompson

Using the test applet and HTML code as on http://segal.org/java/Hello2/, if
I disable Java within Internet Explorer on Windows, the words "Java does not
work" within the applet tags gets displayed as intended (regardless of
whether the Sun or Microsoft JVM is used). However, if I disable Java
within Netscape for Windows, the error message does not appear.

The HTML I am using is:
<APPLET code="Hello.class" WIDTH=130 HEIGHT=40> Java does not work </APPLET>

Check this URL, it goes one step further*..
<http://www.physci.org/codes/jretest.jsp?v=11>

I found Gecko based browsers (NN, Moz)did not
use the 'noapplet' option, that is for browsers
that *do* *not* *understand* the applet tag.

Instead they refer to the 'alt' attribute,
which is for browsers that are choosing to
*ignore* the applet tag.

* you will find a call to 'JavaVersionApplet'
 
M

Mickey Segal

Andrew Thompson said:
Instead they refer to the 'alt' attribute,
which is for browsers that are choosing to
*ignore* the applet tag.

The alt= code does not seem to do the trick either, as shown on
http://segal.org/Hello3/. On Internet Explorer the "alt=" gets displayed
along with the error text, and on Netscape no text is displayed.

Something seems to be making the correct decision about whether Java is
working in your pages:
http://www.physci.org/codes/jretest.jsp
but one gets transferred to the page with the correct answer so it is
difficult to see how it is being done.
 
N

nos

If it is true that AOL owns Netscape, would you
not expect the Netscape implementation to move
to become the same as the AOL browser?
 
M

Mickey Segal

Andrew Thompson said:
That's getting pretty good Mickey.
It is pretty rare that html code
by Java programmers is actually valid.

Yours is, it just lacks two vital bits,
a doctype and content-type.

Everyone can rest assured that usually I use doctype and content-type on
pages with our real applets, though I omit them when doing test pages.

But there is a bigger problem. The approach at
http://segal.org/java/Hello3/ fails on Safari on Macintosh OS X, apparently
because Apple feels little need to support applet tags robustly any more.

Getting desperate, I tried Roedy Green's approach of using an IMG tag to
show Java not working:
http://mindprod.com/jgloss/applet.html
but this was ignored by Safari and Netscape; i.e. treated the same as the
"Java does not work (outside APPLET)" tag on
http://www.segal.org/java/Hello3/.

Is it time to cave in and use OBJECT tags? I dread fussing with new HTML
for the 10 OS/browser/JVM combinations we support, and worry about messy
CLASSID statements for our code that we update many times per week, and
worry about whether this will make troubles for the CAB files we need to
support most Internet Explorer users on Windows.

It would be simpler if Apple acted on the bug report I filed on Safari and
APPLET tags. As Apple told us in 2002:
http://developer.apple.com/document...31MOSX10.2RN/applets/chapter_2_section_2.html
"Sun encourages the use of the <applet> tag for all applets".
 
A

Andrew Thompson

Everyone can rest assured that usually I use doctype and content-type on
pages with our real applets, though I omit them when doing test pages.

But there is a bigger problem. The approach at
http://segal.org/java/Hello3/ fails on Safari on Macintosh OS X, apparently
because Apple feels little need to support applet tags robustly any more.

Well... If you do not specify a doctype,
Safari might presume HTML 4.01 _Strict_.

The APPLET attribute has been deprecated
in HTML 4.01, that is why I use an HTML
4.01 _Transtitional_ doctype (this covers
HTML 3.02, but allows me to use CSS2)

See if Safari does any better with that.

[ I did not point you at the validator for
no reason Mickey. My prinicpal is, get the
HTML valid before you worry about what the
applet is actually doing, or not doing. ]
 
M

Mickey Segal

Andrew Thompson said:
Well... If you do not specify a doctype,
Safari might presume HTML 4.01 _Strict_.

The APPLET attribute has been deprecated
in HTML 4.01, that is why I use an HTML
4.01 _Transtitional_ doctype (this covers
HTML 3.02, but allows me to use CSS2)

See if Safari does any better with that.

OK. Good point. I modified http://segal.org/java/Hello3/, but
unfortunately Safari showed no mercy.
 
M

Mickey Segal

Andrew Thompson said:
Damn! Does it also fail on my page?
(wanders off, muttering incomprehensibly)

With Java turned off in Safari, http://www.physci.org/codes/jretest.jsp
cheerfully reports that all versions of Java work, including 1.5 (Safari
uses 1.4.2 when it is turned on).

One can get around these problems using JavaScript's javaEnabled (as in
http://segal.org/java/configuration/, though the page does not stay
displayed unless you have JavaScript turned off), but this approach fails
with many Mozilla/Netscape versions for Macintosh OS X (which we identify on
that page). However, we were trying to avoid JavaScript for this particular
use since it is for a test page reporting whether Java and JavaScript work.
 
A

Andrew Thompson

With Java turned off in Safari, http://www.physci.org/codes/jretest.jsp
cheerfully reports that all versions of Java work, including 1.5 (Safari
uses 1.4.2 when it is turned on).

Actually I realize now that was
a stupid test. The alt tag is
supposed to appear on the WxH of
the applet area.

Those applets are 0x0 ..which may
not be big enough to contain the
message [ ..D'Uh! (slaps forehead) ]

I suppose in it's proper context
that applet should appear on a page
with a non 0x0 applet, that is its
point after all.

Maybe I should redesign those pages
with the JavaVersionApplet in the
background, _combined_ with a
'You are using Java Version..."
1.1 compatible applet in the main
content.

Thanks again.
 
A

Andrew Thompson

Oh yeah, sorry about that, I have
just altered the source & jar to check
for 1.5, I try to..
Class.forName("java.lang.Appendable")

It redirects my PC (I am running 1.4.2).
 
M

Mickey Segal

Andrew Thompson said:
Oh yeah, sorry about that, I have
just altered the source & jar to check
for 1.5, I try to..
Class.forName("java.lang.Appendable")

Here is what Safari does:

With Java turned off, it reports success for all Java versions, including
1.5.

With Java turned on, it reports success for all Java versions except 1.5,
for which the user is redirected to another page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top