我正在嘗試在Firefox的網頁上查看.doc/.docx微軟文檔文件。當所有失敗我試圖創建一個小程序,將持有Word OLE的實例來查看文檔。查看firefox中java小程序中的word office文檔
我使用org.eclipse.swt.ole.win32.OleClientSite創建了applet,並且在eclipse中它工作正常,我可以看到Word裏面。
我創建了一個.jar文件,我試圖在firefox中的網頁中使用applet。小程序啓動但我看不到任何內容。
這裏是我的applet代碼:
import java.applet.Applet;
public class JWordViewer extends Applet {
org.eclipse.swt.widgets.Display display;
org.eclipse.swt.widgets.Shell swtParent;
java.awt.Canvas awtParent;
public void init() {
Thread thread = new Thread(new Runnable() {
public void run() {
setLayout(new java.awt.GridLayout(1, 1));
awtParent = new java.awt.Canvas();
add(awtParent);
display = new org.eclipse.swt.widgets.Display();
swtParent = org.eclipse.swt.awt.SWT_AWT.new_Shell(display,
awtParent);
swtParent.setLayout(new org.eclipse.swt.layout.FillLayout());
org.eclipse.swt.ole.win32.OleFrame frame = new org.eclipse.swt.ole.win32.OleFrame(
swtParent, org.eclipse.swt.SWT.NONE);
org.eclipse.swt.ole.win32.OleClientSite site;
try {
site = new org.eclipse.swt.ole.win32.OleClientSite(frame,
org.eclipse.swt.SWT.NONE, "Word.Document");
} catch (org.eclipse.swt.SWTException e) {
String str = "Create OleClientSite Error" + e.toString();
System.out.println(str);
return;
}
setSize(500, 500);
validate();
site.doVerb(org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW);
while (swtParent != null && !swtParent.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
});
thread.start();
}
public void stop() {
if (display != null && !display.isDisposed()) {
display.syncExec(new Runnable() {
public void run() {
if (swtParent != null && !swtParent.isDisposed())
swtParent.dispose();
swtParent = null;
display.dispose();
display = null;
}
});
remove(awtParent);
awtParent = null;
}
}
}
`
任何想法,爲什麼不工作?
以下是Java控制檯說:
basic: Told clients applet is started Exception in thread "Thread-11" java.lang.ExceptionInInitializerError at org.eclipse.swt.widgets.Display.<clinit>(Display.java:130) at JWordViewer$1.run(JWordViewer.java:17) at java.lang.Thread.run(Unknown Source) Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission sun.arch.data.model read) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPropertyAccess(Unknown Source) at java.lang.System.getProperty(Unknown Source) at org.eclipse.swt.internal.Library.loadLibrary(Library.java:167) at org.eclipse.swt.internal.Library.loadLibrary(Library.java:151) at org.eclipse.swt.internal.C.<clinit>(C.java:21) ... 3 more
而這之後我告訴了信任該applet ...
您正在收到拒絕訪問錯誤。你有權限閱讀文件嗎? – 2010-02-03 15:38:26