简体   繁体   中英

Embed Java applet through URL data

I'm trying to explore URL data capabilities to embed in HTML Java applet.

The documentation, for HTML tags to instantiation a java applet 1 , don't exclude this option but I don't seem to be able to to this.

I have different variations of HTML tags values using (object and applet) and what I think came close to my goal was this:

<object type="application/x-java-applet" width="100" height="100">
  <param name="archive" value="data:application/java-archive;base64,BASE64_OF_JAR"/>
  <param name="code" value="test.class"/>
  <h1>not working</h1>
</object>

This variation result in an IlegalArgumentException with text "name". I check this clicking on the Error Icon on the Browser. On The java console the whole stack trace is:

java.net.MalformedURLException: unknown protocol: data
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at sun.plugin.util.ProgressMonitorAdapter.setProgressFilter(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager.setupProgress(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

Does anyone have an idea about how to do this or if it's not possible?

PS: There's an example of how to embed an JNLP in HTML by Oracle here

The HTML4 specification for OBJECT element allows inline data embed through URL DATA and the Applet instantiation documentation from Oracle also allows this. The tests performed show the Java browser plugin (from Oracle), and the available source code from Java SE 6 , shows that the implementation doesn't support it.

In this case, doesn't seem to matter if the browser support it, because the resource handling of resources reference in the Object/Applet HTML Element are performed by the browser plugin.

An alternative would be to be use applet deserialization, serialized through URL DATA, using the OBJECT attribute of APPLET element . As mentioned in the HTML4 specification, there is no active support for APPLET and OBJECT attribute, and JRE doesn't seem to support Object deserialization from URL DATA too.

In a nutshell, JRE doesn't support base64 deserialization in the CODE, OBJECT and ARCHIVE HTML attributes.

There is also a BUG regarding URL DATA support in JRE1.4.1 that wasn't fulfilled Bug ID: 4756961 .

The results of my tests with JRE7 in a 64 bits Windows machine are the following:

  • Passing a JAR through URL DATA to ARCHIVE attribute results in an IllegalArgumentException in Applet2Manager.loadJarFiles();
  • Passing a class through URL DATA to CODE attribute results in a ClassNotFoundException in Applet2ClassLoader.findClass();
  • Passing a serialized applet through URL DATA to OBJECT attribute results in a FileNotFoundException in Plugin2ClassLoader.getResourceAsResource().

即使HTML标准允许,JRE通常也不了解base64编码数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM