我想在动态Web项目中使用Java Applet,但无法正常工作。 我创建了一个小程序:
`public class MyApplet extends JApplet {
static final long serialVersionUID = 1L;
private JTextField textField;`
/**
* Create the applet.
*/
public MyApplet() {
getContentPane().setLayout(null);
JLabel lblTag = new JLabel("Tag:");
lblTag.setBounds(91, 51, 46, 14);
getContentPane().add(lblTag);
textField = new JTextField();
textField.setBounds(126, 48, 86, 20);
getContentPane().add(textField);
textField.setColumns(10);
}
}`
然后我将其放入.JAR文件
接下来,我创建了Dynamic Web Project,并在index.html文件所在的文件夹中分配.JAR文件。
我也放
`<applet code="MyApplet.class" archive="name.jar" width="500" height="500" ></applet>`
到index.html文件。
当我在apache服务器上打开此项目时,我可以正确看到带有样式的html文件,但aplet没有显示。它发生在每个浏览器中。我在控制台中没有任何错误:
`sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.5.37
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Dec 12 2018 12:07:02 UTC
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.5.37.0
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 10
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.0
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jre1.8.0_121
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_121-b13
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\Admin\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Users\Admin\Desktop\Projekty PWJJ\apache-tomcat-8.5.37\apache-tomcat-8.5.37
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\Admin\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Users\Admin\Desktop\Projekty PWJJ\apache-tomcat-8.5.37\apache-tomcat-8.5.37
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\Admin\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Users\Admin\Desktop\Projekty PWJJ\apache-tomcat-8.5.37\apache-tomcat-8.5.37\endorsed
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1250
sty 20, 2019 9:13:47 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_121\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_121/bin/server;C:/Program Files/Java/jre1.8.0_121/bin;C:/Program Files/Java/jre1.8.0_121/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\MinGW\bin;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Users\Admin\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Nmap;C:\Users\Admin\AppData\Local\GitHubDesktop\bin;C:\WINDOWS\system32;;.]
sty 20, 2019 9:13:47 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
sty 20, 2019 9:13:47 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
sty 20, 2019 9:13:47 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
sty 20, 2019 9:13:47 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
sty 20, 2019 9:13:47 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 608 ms
sty 20, 2019 9:13:47 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
sty 20, 2019 9:13:47 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.37
sty 20, 2019 9:13:48 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
sty 20, 2019 9:13:48 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
sty 20, 2019 9:13:48 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 274 ms`
答案 0 :(得分:0)
这不适用于现代浏览器。允许运行Applet的Java插件在相当长的一段时间内已经过时,例如Firefox did this in 2016:
当前使用诸如Silverlight或Java之类的插件的网站和发布者应加快向Web技术的过渡。 Web平台功能强大,通常可以执行插件可以执行的所有操作。在极少数站点需要扩展Web技术的情况下,推荐的解决方案是将其他功能开发为Firefox附加组件。网站维护人员应做好准备,要求插件在2016年底之前停止在所有版本的Firefox中运行。