2011-12-23 60 views
1

我需要一些幫助,在我的jnlp應用程序showDocument。 我試圖在瀏覽器的另一個選項卡中顯示一個pdf文件,但是java插件被拒絕。權限在jnlp中被拒絕嘗試調用showDocument與pdf文件

我的JNLP文件具有

<security> 
     <all-permissions/> 
    </security> 

,我的代碼是:

AccessController.doPrivileged(new PrivilegedAction() 
    { 
     @Override 
     public Object run() 
     { 
      try 
      { 
       applet.getAppletContext().showDocument(new URL("file:///C:/Contrato.PDF"), "_blank"); 
      } 
      catch(Exception e) 
      { 
       e.printStackTrace(); 
       showException("Erro ao exibir arquivo:" + e.getMessage()); 
      } 
      return null; 
     } 
    }); 

,但我收到異常

java.lang.SecurityException: showDocument url permission denied 

如果我嘗試做showDocument(google.com ,_blank)...,但當我嘗試顯示任何文件時,它不起作用。

+0

'showDocument(new URL(「file:/// C:/Contrato.PDF」),「_blank」);' - 'showDocument' was * not * designed for shown off off off off the computer of end用戶!該PDF是在客戶端還是服務器上? – 2011-12-24 20:09:57

+0

在客戶端 – 2012-01-04 22:09:55

回答

2

showDocument(URL)方法AppletContext從未打算從本地文件系統啓動文件(即使指定爲file協議URL)。

至少有兩個選擇:

  1. 的JNLP片段表明,這是一個值得信賴的應用程序,所以對於一個1.6+應用程序,Desktop.browse(URI)可以調用。
  2. JNLP API的BasicService提供了showDocument(URL)方法。
+0

桌面類解決了問題。 Ty – 2012-04-04 20:45:18

+0

不客氣。發佈代碼以清除問題+1。 – 2012-04-05 01:20:15