从Angular 10中的JAR文件运行小程序

huangapple go评论69阅读模式
英文:

Run applet from jar in Angular 10

问题

我必须在 Angular 10 应用程序中从其 JAR 文件中运行 Java Applet,在 Chrome、IE11 和 Edge 上都尝试过,但所有尝试都没有成功。

我已经完成了以下操作:

  • 将 JAR 文件放在组件的 Angular 文件夹中(与组件的 HTML、SCSS 和 TS 文件一起);
    我在 HTML 文件中添加了以下内容:
<script language="Javascript">

    var _app = navigator.appName;

    if (_app == 'Mozilla') {
      document.write('<embed code="MyClass.class"',
        'width="200"',
        'height="200"',
        'type="application/x-java-applet;version=1.8.0">');
    }
    else if (_app == 'Microsoft Internet Explorer') {
      document.write('<OBJECT ',
        'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"',
        'width="200"',
        'height="200">',
        '<PARAM name="code" value="MyClass.class">',
        '</OBJECT>');
    }
    else {
      document.write('<p>Sorry, unsupported browser.</p>');
    }

</script>

以及这个:

<object
  codetype="application/java" classid="java:TableManager.class"
  classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
  archive="my_jar.jar" width="740" height="400">
  <param name="code" value="MyClass.class">
</object>

还有这个:

<applet code="MyClass.class" archive="my_jar.jar" type="application/x-java-applet" height="300" width="550"></applet>

但是什么都没有起作用,你有什么建议吗?

英文:

I have to run a Java applet from his jar in an Angular 10 application, I've tried to run on Chrome, IE11 and Edge but all my tries did not work.

I've done the following things:

  • put the jar file inside the Angular folder of my component (with the html, scss and ts files of the component);
    I've added, in the html file, both this:

    &lt;script language=&quot;Javascript&quot;&gt;
    
      var _app = navigator.appName;
    
      if (_app == &#39;Mozilla&#39;) {
        document.write(&#39;&lt;embed code=&quot;MyClass.class&quot;&#39;,
          &#39;width=&quot;200&quot;&#39;,
          &#39;height=&quot;200&quot;&#39;,
          &#39;type=&quot;application/x-java-applet;version=1.8.0&quot;&gt;&#39;);
      }
      else if (_app == &#39;Microsoft Internet Explorer&#39;) {
        document.write(&#39;&lt;OBJECT &#39;,
          &#39;classid=&quot;clsid:8AD9C840-044E-11D1-B3E9-00805F499D93&quot;&#39;,
          &#39;width=&quot;200&quot;&#39;,
          &#39;height=&quot;200&quot;&gt;&#39;,
          &#39;&lt;PARAM name=&quot;code&quot; value=&quot;MyClass.class&quot;&gt;&#39;,
          &#39;&lt;/OBJECT&gt;&#39;);
      }
      else {
        document.write(&#39;&lt;p&gt;Sorry, unsupported browser.&lt;/p&gt;&#39;);
      }
    
    &lt;/script&gt;
    

and this:

&lt;object
  codetype=&quot;application/java&quot; classid=&quot;java:TableManager.class&quot;
  classid=&quot;clsid:8AD9C840-044E-11D1-B3E9-00805F499D93&quot;
  archive=&quot;my_jar.jar&quot; width=&quot;740&quot; height=&quot;400&quot;&gt;
  &lt;param name=&quot;code&quot; value=&quot;MyClass.class&quot;&gt;
&lt;/object&gt;

and this:

&lt;applet code=&quot;MyClass.class&quot; archive=&quot;my_jar.jar&quot; type=&quot;application/x-java-applet&quot; height=&quot;300&quot; width=&quot;550&quot;&gt;&lt;/applet&gt;

But nothing worked, do you have any suggestions?

答案1

得分: 1

许多现代网络浏览器已经不再支持Java小程序,而那些仍支持的浏览器也需要用户明确启用支持。

为什么?因为用于网络浏览器的Java插件以其安全漏洞而臭名昭著,这些漏洞使得用户可能因恶意小程序而面临计算机被入侵的风险。

我的建议是,您应当调整应用架构,避免在用户的浏览器中运行Java。

如果您无法这样做,Oracle的这个页面提供了针对不同网络浏览器的指南,教您如何在浏览器中启用Java:

请注意,这些指南需要用户自行按照执行。

英文:

Many modern web browsers don't support Java applets at all anymore, and those that do require the user to explicitly enable support.

Why? Because Java plugins for web browsers were notorious for security flaws that put the user of risk of having their computer hacked via a malicious applet.

My recommendation is that you change your application architecture to avoid any need of running Java in the user's browser.

If you can't do that, this Oracle page gives instructions for various web browsers on how to get Java working in the browser:

Note that the instructions need to be followed by the end user.

huangapple
  • 本文由 发表于 2020年9月22日 19:28:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/64008785.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定