在这里,我创建了一个小程序,从服务器路径下载文本文件并保存到 ubuntu 中的 /tmp/ 和 windowsXP 中的 C:windows/temp/ 作为 OLFile 并将其发送到默认打印机,它仅在 ubuntu OS 中工作,但是它不适用于 WindowsXP 的 firefox。如果我从eclipse(在windowsXP中)运行applet源文件,它就可以工作。java控制台可能会在firefox(来自windowsXP)中加载Applet时在线程中输出一些异常。为什么会这样?我可以在 Windows 中配置任何东西吗?Java 控制台输出(来自 windowsXP)和小程序源代码如下所示。你能帮我么....
控制台输出:
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();
}
}
}