简体   繁体   English

通过URL数据嵌入Java小程序

[英]Embed Java applet through URL data

I'm trying to explore URL data capabilities to embed in HTML Java applet. 我正在尝试探索嵌入HTML Java applet的URL数据功能。

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. 用于实例化java applet 1的 HTML标记的文档不排除此选项,但我似乎无法解决此问题。

I have different variations of HTML tags values using (object and applet) and what I think came close to my goal was this: 我使用(对象和小程序)有不同的HTML标记值变体,我认为接近我的目标是:

<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". 此变体导致带有文本“name”的IlegalArgumentException。 I check this clicking on the Error Icon on the Browser. 我点击浏览器上的错误图标。 On The java console the whole stack trace is: 在java控制台上,整个堆栈跟踪是:

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 PS:有如何在HTML甲骨文嵌入JNLP的例子在这里

The HTML4 specification for OBJECT element allows inline data embed through URL DATA and the Applet instantiation documentation from Oracle also allows this. OBJECT元素的HTML4规范允许通过URL DATA嵌入的内联数据和Oracle的Applet实例化文档也允许这样做。 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. 所执行的测试显示了Java浏览器插件(来自Oracle),以及来自Java SE 6的可用源代码,表明该实现不支持它。

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. 在这种情况下,浏览器是否支持它似乎并不重要,因为对象/小程序HTML元素中的资源引用的资源处理是由浏览器插件执行的。

An alternative would be to be use applet deserialization, serialized through URL DATA, using the OBJECT attribute of APPLET element . 另一种方法是使用applet反序列化,通过URL DATA序列化,使用APPLET元素的OBJECT属性。 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. 正如HTML4规范中所提到的,对APPLET和OBJECT属性没有主动支持,并且JRE似乎也不支持来自URL DATA的对象反序列化。

In a nutshell, JRE doesn't support base64 deserialization in the CODE, OBJECT and ARCHIVE HTML attributes. 简而言之,JRE不支持CODE,OBJECT和ARCHIVE HTML属性中的base64反序列化。

There is also a BUG regarding URL DATA support in JRE1.4.1 that wasn't fulfilled Bug ID: 4756961 . 在JRE1.4.1中还有一个关于URL DATA支持的BUG未实现错误ID:4756961

The results of my tests with JRE7 in a 64 bits Windows machine are the following: 我在64位Windows机器上使用JRE7进行测试的结果如下:

  • Passing a JAR through URL DATA to ARCHIVE attribute results in an IllegalArgumentException in Applet2Manager.loadJarFiles(); 将JAR通过URL DATA传递给ARCHIVE属性会导致Applet2Manager.loadJarFiles()中出现IllegalArgumentException;
  • Passing a class through URL DATA to CODE attribute results in a ClassNotFoundException in Applet2ClassLoader.findClass(); 通过URL DATA将类传递给CODE属性会导致Applet2ClassLoader.findClass()中的ClassNotFoundException;
  • Passing a serialized applet through URL DATA to OBJECT attribute results in a FileNotFoundException in Plugin2ClassLoader.getResourceAsResource(). 将序列化小程序通过URL DATA传递到OBJECT属性会导致Plugin2ClassLoader.getResourceAsResource()中出现FileNotFoundException。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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