gpt4 book ai didi

Java Applet 无法在 Windows XP 中运行

转载 作者:行者123 更新时间:2023-12-01 13:52:37 28 4
gpt4 key购买 nike

这里我创建了一个小程序,从服务器路径下载一个文本文件并保存到 ubuntu 中的/tmp/和 windowsXP 中的 C:windows/temp/作为 OLFile 并将其发送到默认打印机,它在 ubuntu 操作系统中工作仅限,但它不能与 WindowsXP 中的 Firefox 一起使用。如果我从 eclipse(在 windowsXP 中)运行小程序源文件,它就可以工作。在 firefox(来自 windowsXP)中加载 Applet 时,java 控制台可能会在线程中输出一些异常。为什么会出现这样的情况呢?我需要在 Windows 中配置任何内容吗?java 控制台输出(来自 windowsXP)和 applet 源代码如下所示。你能帮我一下吗......

控制台输出:

 Exception in thread "AWT-EventQueue-2" java.lang.IllegalStateException: Applet's parent container not set up
at sun.plugin2.applet.Plugin2Manager.start(Unknown Source)
at sun.plugin2.main.client.PluginMain$StartAppletRunner.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Java小程序源代码:

 import java.applet.Applet;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;



public class FilePrintApplet extends Applet
{
/**
*
*/


public void start()
{

try {
String server=this.getParameter("SERVER");
String filename=this.getParameter("FILENAME");

String osname=System.getProperty("os.name");
String filePath="";

URL url = new URL("http://"+server+"/openLypsaa/reports/report_oc/"+filename);

URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();

if("Linux".equals(osname))
{
filePath = "/tmp/OLFile";
}
else
{
filePath = "C:\\\\WINDOWS\\\\Temp\\\\OLFile";
}

OutputStream output = new FileOutputStream(filePath);

byte[] buffer = new byte[256];
int bytesRead = 0;
while ((bytesRead = is.read(buffer)) != -1)
{
System.out.println(bytesRead);
output.write(buffer, 0, bytesRead);
}
output.close();
if("Linux".equals(osname))
Runtime.getRuntime().exec("lp /tmp/OLFile").waitFor();
else
Runtime.getRuntime().exec("print C:\\\\WINDOWS\\\\Temp\\\\OLFile").waitFor();
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

最佳答案

我的观察..

Applet 通过 jvm 以有限的权限运行,Applet 应该在客户端计算机上运行,​​因此限制访问文件系统。

  • Eclipse 通过 appletViewer 启动小程序,并且很可能没有安全限制,因此如果在 Eclipse 中适合您,这是有意义的。
  • 在 ubuntu 上/tmp/目录是全局可访问的,因此在 ubuntu 上也能正常工作
  • 在 Windows 上,C:windows/temp/目录可能没有写入权限,因此失败。

here详细讨论。

关于Java Applet 无法在 Windows XP 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19856412/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com