4

Just out of curiosity, between <applet> vs <object> for a Java applet, which one should I use? I know that <applet> is deprecated, however Sun still recommends the use of <applet>.

Is there any drawback between the two tags? Because when I use <object> for Mac in Safari, it causes a problem saying that the page can't load, even though the page loaded properly, and when I check the activity window it said that the class was not found/cancelled. For example:

enter image description here

Kijewski
  • 25,517
  • 12
  • 101
  • 143
Harts
  • 4,023
  • 9
  • 54
  • 93

4 Answers4

6

Use applet if you have found that it works more often. The object element was introduced as a theoretical unification that would be a catch-all for any embedding of external data. It never worked well, and modern HTML development has effectively abandoned the unification idea. HTML5 introduces audio and video, for example and keeps img (logical unification would surely deprecate img, because an image can be embedded with object).

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
4

Use deployJava.js as mentioned in the applet info. page..

..To avoid browser compatibility issues, the Deployment Toolkit script provides JavaScript functions that automatically generate the HTML required to deploy RIAs. Developers should invoke these functions to deploy their solutions in a consistent fashion across various browsers.

Then you don't have worry about whether the script writes an applet, object or embed element.


As an aside. Copy/pasting the text from the Activity window would be a lot more useful than a screen-shot. Now I look (squint) at it, it seems the only two lines of output that are in any way relevant are:

The css/none is not a class or a Jar, and neither of them exist on the server. So that applet has problems beyond the HTML elements used to deploy it.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

Use <object>. <applet> was deprecated back in HTML 4.01.

Unless you're targeting a stone-age environment, there is not reason to acknowledge the existence of the applet tag.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • 4
    but why in oracle site http://docs.oracle.com/javase/1.5.0/docs/guide/plugin/developer_guide/using_tags.html#mixed "Note: The HTML specification states that the applet tag is deprecated, and that you should use the object tag instead. However, the specification is vague about how browsers should implement the object tag to support Java applets, and browser support is currently inconsistent. Sun therefore recommends that you continue to use the applet tag as a consistent way to deploy Java applets across browsers on all platforms." I know it's 1.5. I need to use it for cross platform – Harts Apr 09 '12 at 16:29
  • applet will still work, but at some point support for it will be dropped. That could be tomorrow, or it could be in 500 years. If you're going for standards-compliant markup, then don't use it. – Marc B Apr 09 '12 at 16:46
  • 1
    It's entirely OK if your mark-up is marked up as HTML 3.2. ;) – Andrew Thompson Apr 09 '12 at 16:47
  • @Harts You are right, and so they provided the javascript workaround. Going forward, the w3c _did_ clarify the _object_ tag, so in time this wrinkle will work itself out as browsers better support HTML 5. – Edwin Buck Apr 09 '12 at 16:51
  • 1
    @MarcB Unless you can provide a solution to the OP's problem, I don't think your answer is a very good one. – Mr Lister Apr 09 '12 at 16:57
  • 2
    @Mr Lister: How could anyone provide a solution if the OP doesn't actually post his `` code? Screen captures of files being loaded a rather useless. – Marc B Apr 09 '12 at 16:59
  • 1
    In that case, you should post a comment asking for more details. Mind you, I don't have a better answer than you, but if someone has a problem with using ``, just saying "well, use it anyway, tough luck" is not right. – Mr Lister Apr 09 '12 at 17:03
  • Actually, the right answer is to ditch 10+ year-old obsolete html constructs and start working with the currently globally recommended solutions. The more people keep stone-age garbage around, the longer it takes to being able to ditch 10+ years worth of hacks/workarounds to support that stone age tech. Hence me saying to use object, and ignore oracle's suggestion. If you do `` right, it works everywhere 'modern', and the places it doesn't should be thrown on the trash heap and forgotten. – Marc B Apr 09 '12 at 17:05
0

I think Sun has a point. HTML5 says:

The applet element is now obsoleted so that all extension frameworks (Java, .NET, Flash, etc) are handled in a consistent manner.

In other words, it's no longer valid for reasons of theoretical purity and not because of any practical problem. Frankly, I find <applet> simpler and more reliable to use in the real world and continue to use it.

While deployJava.js might hide the gory details away, the reality is that under the hood, it still uses <applet> in some circumstances.

Alohci
  • 78,296
  • 16
  • 112
  • 156