无法在Eclipse中使用JavaScript代码从html显示小程序 [英] Can't display applet from html using javascript code in Eclipse

查看:256
本文介绍了无法在Eclipse中使用JavaScript代码从html显示小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Eclipse IDE中的JavaScript代码运行一个java小程序,如网页将Java Applet嵌入到.html文件中。但输出页面显示错误。我使用applet的代码是

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

在头部和

 <脚本> 
var attributes = {
codebase:'../src/',
code:'transfol.Main.class',
// archive:'my-archive.jar ',
width:'800',
height:'500'
};
var parameters = {
java_arguments:'-Xmx256m'
}; //根据您的需要自定义
var version ='1.5'; // JDK version
deployJava.runApplet(attributes,parameters,version);
< / script>

在正文部分。



导航器中显示的方式为
包含在src文件夹(在Eclipse中)和index.jsp中的包transvert中的Main.class在web内容中



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



我几乎肯定问题是在代码库或代码属性中,必须指定路径,当我点击applet的更多信息时,我会收到例外:


发生了异常事件。有关更多信息,请尝试从命令行启动浏览器并检查输出。
有关更多信息,请访问 http://icedtea.classpath.org/wiki / IcedTea-Web ,并按照此处介绍的步骤来获取文件错误的必要信息
附加信息可能在控制台或日志中可用。

另一个可用的信息:
IcedTea-Web插件版本:1.5(1.5 -1ubuntu1)
26/5/15 5:56 PM
异常是:

  net.sourceforge .jnlp.LaunchException:致命:初始化错误:无法初始化小程序。欲了解更多信息,请点击更多信息按钮。 
在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:746)
在net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:675)
在net.sourceforge .jnlp.Launcher $ TgThread.run(Launcher.java:908)
导致:java.lang.ClassNotFoundException:无法执行代码库查找,没有jar。在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:716)
...更多

这是启动您的小程序时发生的异常列表。请注意,这些例外可能来自多个小程序。对于有用的错误报告,请确保仅运行一个小程序。
1)at 26/5/15 5:47 PM
net.sourceforge.jnlp.LaunchException:致命:初始化错误:无法初始化小程序。欲了解更多信息,请点击更多信息按钮。
在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:746)
在net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:675)
在net.sourceforge .jnlp.Launcher $ TgThread.run(Launcher.java:908)
导致:java.lang.ClassNotFoundException:无法执行代码库查找,没有jar。在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:716)
... 2更多


解决方案

尝试这个



Java applet



  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;字符串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;}});退回} public void destroy(){} public void destroy(){}}  



HTML



 < script> <! -  applet id可用于获取对applet对象的引用 - > 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) ;  



不要忘记签名你的小程序,您的应用程式带有这样的下划线'_'的网址。


I've tried to run a java applet using the javascript code in Eclipse IDE as shown in the web page Embedding Java Applet into .html file. But the output page shows error. My code to use applet is

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

in the head section and

<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>

in the body section.

The way I've saved them is shown in the Navigator as Main.class inside the package transfol which is in src folder (in Eclipse) and index.jsp in the web content

where Main.class is the applet and index.jsp is the file from which applet is being called.

I'm almost sure that the problem is in the codebase or code attributes where the path has to be specified, when I click on more information on applet, I get exception as:

The folloing exception has occured. For more information, try to launch the browser from the command line and examine the output. For even more information you can visit http://icedtea.classpath.org/wiki/IcedTea-Web and follow the steps described there on how to obtain necessary information to file bug Additional information may be available in the console or logs. Even more information is available if debugging is enabled.

Another available info: IcedTea-Web Plugin version: 1.5 (1.5-1ubuntu1) 26/5/15 5:56 PM Exception was:

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

解决方案

Try this

Java applet

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>

Call via javascript

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

Don't forget to sign your applet and to not run your app with a URL with underscores '_' like this.

这篇关于无法在Eclipse中使用JavaScript代码从html显示小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆