Java Applet没有在Windows XP中运行

时间:2013-11-08 10:10:34

标签: java eclipse applet

在这里我创建了一个applet,从服务器路径下载文本文件并保存到ubuntu中的/ tmp /和C:windows / temp /在windowsXP中作为OLFile并将其发送到默认打印机,它在ubuntu OS中工作只是,但它不能与WindowsXP的Firefox一起使用。如果我从eclipse运行applet源文件(在windowsXP中)它可以工作。在Firefox中加载Applet时,java控制台可能会在线程中输出一些Exception(来自windowsXP)。为什么会这样发生?我可以在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 applet源代码:

 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();
    }
}
}

1 个答案:

答案 0 :(得分:1)

我的观察......

小程序由jvm以有限的权限运行,小程序应该在客户端计算机上运行,​​因此仅限于访问文件系统。

  • Eclipse通过appletViewer启动applet,很可能没有安全限制,所以在Eclipse中为你工作是有意义的。
  • ubuntu / tmp /目录上的
  • 是全局可访问的,因此在ubuntu上也可以使用
  • 在Windows上,C:windows / temp /目录可能没有写入权限,因此失败。

here详细讨论了。