【问题标题】:Can't display applet from html using javascript code in Eclipse无法在 Eclipse 中使用 javascript 代码从 html 显示小程序
【发布时间】:2015-05-26 12:30:20
【问题描述】:

我尝试使用 Eclipse IDE 中的 javascript 代码运行 java 小程序,如网页 Embedding Java Applet into .html file 中所示。但是输出页面显示错误。我使用小程序的代码是

<script src="//www.java.com/js/deployJava.js"></script>

在头部和

<script>
    var attributes = {
        codebase : '../src/',
        code : 'transfol.Main.class',
        //archive: 'my-archive.jar',
        width : '800',
        height : '500'
    };
    var parameters = {
        java_arguments : '-Xmx256m'
    }; // customize per your needs
    var version = '1.5'; // JDK version
    deployJava.runApplet(attributes, parameters, version);
</script>

在正文部分。

我保存它们的方式在导航器中显示为 src 文件夹(在 Eclipse 中)中的包 transfol 中的 Main.class 和 Web 内容中的 index.jsp

其中 Main.class 是小程序,index.jsp 是从中调用小程序的文件。

我几乎可以肯定问题出在必须指定路径的代码库或代码属性中,当我单击有关小程序的更多信息时,出现以下异常:

发生了以下异常。有关更多信息,请尝试从命令行启动浏览器并检查输出。 如需更多信息,您可以访问http://icedtea.classpath.org/wiki/IcedTea-Web 并按照其中描述的步骤了解如何获取必要信息以提交错误 控制台或日志中可能会提供其他信息。如果启用调试,则可以获得更多信息。

另一个可用信息: IcedTea-Web 插件版本:1.5 (1.5-1ubuntu1) 26/5/15 下午 5:56 例外是:

net.sourceforge.jnlp.LaunchException: Fatal: Initialization Error: Could not initialize applet. For more information click "more information button".
    at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:746)
    at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:675)
    at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:908)
Caused by: java.lang.ClassNotFoundException: Can't do a codebase look up and there are no jars. Failing sooner rather than later
    at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:716)
    ... 2 more
This is the list of exceptions that occurred launching your applet. Please note, those exceptions can originate from multiple applets. For a helpful bug report, be sure to run only one applet. 
1) at 26/5/15 5:47 PM
net.sourceforge.jnlp.LaunchException: Fatal: Initialization Error: Could not initialize applet. For more information click "more information button".
    at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:746)
    at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:675)
    at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:908)
Caused by: java.lang.ClassNotFoundException: Can't do a codebase look up and there are no jars. Failing sooner rather than later
    at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:716)
    ... 2 more

【问题讨论】:

    标签: java javascript eclipse applet webpage


    【解决方案1】:

    试试下面的代码

     <APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
     </APPLET>
    

     <object width="400" height="400" data="helloworld.class"></object> 
    

    【讨论】:

    • 感谢您的回复,但它不起作用。结果是一样的,只是小程序空间上显示了一个错误
    【解决方案2】:

    试试这个

    Java 小程序

    package cdig;
    
    import java.applet.Applet;
    import java.security.AccessController;
    import java.security.PrivilegedAction;
    
    public class CDigApplet extends Applet
    {
    
    	private static final long serialVersionUID = 1L;
    
    	String ret;
    
    	CDigApplet applet = this;
    
    	@SuppressWarnings({ "rawtypes", "unchecked" })
    	public String signFile(String fileID, String pin, String token)
    	{
    		AccessController.doPrivileged(new PrivilegedAction()
    		{
    			@Override
    			public Object run()
    			{
    				try
    				{
    					System.out.println("Iniciando processo de assinatura.");
    				}
    				catch (Exception e)
    				{
    					String sl = "{\"success\":false," + "\"message\":\"" + e.getMessage() + "\"}";
    					ret = sl;
    					System.out.println(sl);
    				}
    
    				return null;
    			}
    		});
    
    		return ret;
    	}
    
    	public void init(){
    	}
    
    	public void destroy(){
    	}
    
    }

    HTML

    <script>
        <!-- applet id can be used to get a reference to the applet object -->
        var attributes = { id:'cdigApplet', code:'cdig.CDigApplet', archive:'cdig-applet-1.0.jar', width:1, height:1, classloader_cache:'false'} ;
        var parameters = {persistState: false, cache_option:'no' } ;
        deployJava.runApplet(attributes, parameters, '1.8');
    </script>

    通过javascript调用

    var res = document.getElementById("cdigApplet").signFile(Id, '', token);

    不要忘记签署您的小程序,并且不要使用带有下划线“_”的 URL 运行您的应用程序。

    【讨论】:

      猜你喜欢
      • 2012-02-16
      • 2012-04-16
      • 2015-01-10
      • 2013-01-12
      • 1970-01-01
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 2017-11-02
      相关资源
      最近更新 更多