Reputation: 137
Here I created an applet, to download a text file from server path and saved to /tmp/ in ubuntu and C:windows/temp/ in windowsXP as OLFile and also send it to a default printer, its works in ubuntu OS only, but it wont work with firefox from WindowsXP. If I run applet source file from eclipse(in windowsXP) it works. The java console may output some Exception in thread while loading the Applet in firefox(from windowsXP). Why this happen like this? Can I need to configure anything in windows? The java console output (from windowsXP) and applet source code shown below. Can you please help me....
Console Output:
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 source code:
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();
}
}
}
Upvotes: 0
Views: 1432
Reputation: 1853
My Observations..
Applets run with limited privilege by jvm, applets are supposed to run on client machine and hence restricted to access file system.
here discussed in details.
Upvotes: 2