2011-03-23 40 views
5

我非常需要您的專業知識來解決Windows 7的問題。如何在Windows 7中將URL參數從Java傳遞到本地HTML文件?

場景:我有一個基於框架的幫助軟件包,它設置了上下文相關的幫助調用。 Java應用程序可以通過將代表所需HTML名稱錨點的標記傳遞給稱爲pophelp的HTML文件來控制幫助包打開的頁面。該文件具有javascripting,它從URL的末尾讀取傳遞的標記,並將其映射到幫助包中的相應HTML文件並將其打開。

問題:以上情景工作在Windows XP中,但不再在Windows 7

從Java應用程序調用機制: RUNDLL32 URL.DLL,FileProtocolHandler文件://filepath/pophelp.html ?標籤

到目前爲止發現的結果摘要:似乎url.dll不再允許參數在Windows 7中通過URL傳遞。參數正在被剝離。我也使用Java的Desktop.getDesktop()。browse()嘗試了相同類型的調用,但它似乎也在.html之後去除了所有參數。

示例代碼:

原始呼叫在Windows XP下運行 -

運行命令: RUNDLL32 URL.DLL,FileProtocolHandler文件:// C:\ Program Files文件\應用系統\ App-Editor-8.0.1 \ help \ pophelp.html?TAG = callsubflow

結果:?TAG = callsubflow沒有通過。使用Desktop.getDesktop)

新代碼()瀏覽( -

public static void main(String[] args) { 

    String url = "file:///C:/Program Files/App System/App-Editor-8.0.1/help/pophelp.html?TAG=callsubflow"; 

    try { 
     if (Desktop.isDesktopSupported()) { 
      Desktop desktop = Desktop.getDesktop(); 
        if (desktop.isSupported(Desktop.Action.BROWSE)) { 
         desktop.browse(new URI(url.replace(" ", "%20"))); 
      } 
     } 

    } catch (IOException e) { 
     System.out.println("Unable to open "+url+": "+e.getMessage()); 

    } catch (URISyntaxException e) { 
     e.printStackTrace(); 
    } 

} 

結果:? TAG = callsubflow不通過。

任何援助將不勝感激!

+2

BasicService似乎爲[谷歌於Java(http://www.google.com/search?q=java)工作,告訴他們這樣看來這個是本地文件特有的。在這種情況下,我的WAG認爲這是某種「安全升級」(雖然不要求我解釋它),而在本地文件中進行了更改。 – 2011-03-23 15:33:49

+0

我在想同樣的事情,但似乎很瘋狂,因爲沒有解決方法或設置可以在需要時進行此項工作。我不喜歡我的電腦口述我能做什麼,也不能做絕對的事情。 – 2011-03-23 23:40:57

回答

2

我真的不知道爲什麼Windows刪除本地文件的參數。正如評論中提到的那樣,這是對安全性的一些奇怪的限制。但是我曾經有過類似的問題,我發現了一種適合這種情況的解決方法。
只需創建一個本地臨時HTML文件(不帶參數),將其重定向到所需的參數。
看一看這兩種方法:

// creates w3c conform redirect HTML page 
public String createRedirectPage(String url){ 
    return "<!DOCTYPE HTML>" + 
      "<meta charset=\"UTF-8\">" + 
      "<meta http-equiv=\"refresh\" content=\"1; url=" + url + "\">" + 
      "<script>" + 
      "window.location.href = \"" + url + "\"" + 
      "</script>" + 
      "<title>Page Redirection</title>" + 
      "<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->" + 
      "If you are not redirected automatically, follow the <a href='" + url + "'>link</a>"; 
} 

// creates temporary file with content of redirect HTML page 
public URI createRedirectTempFile(String url) {   
    BufferedWriter writer = null; 
    File tmpFile = null; 
    try { 
     // creates temporary file 
     tmpFile = File.createTempFile("pophelp", ".html", null); 
     // deletes file when the virtual machine terminate 
     tmpFile.deleteOnExit(); 
     // writes redirect page content to file 
     writer = new BufferedWriter(new FileWriter(tmpFile)); 
     writer.write(createRedirectPage(url)); 
     writer.close(); 
    } 
    catch (IOException e) { 
     return null; 
    } 
    return tmpFile.toURI(); 
} 

現在,您可以用這些像這樣:

String url = "file:///C:/Program Files/App System/App-Editor-8.0.1/help/pophelp.html?TAG=callsubflow"; 

if (Desktop.isDesktopSupported()) { 
    Desktop desktop = Desktop.getDesktop(); 
    if (desktop.isSupported(Desktop.Action.BROWSE)) { 
     desktop.browse(createRedirectTempFile(url.replace(" ", "%20"))); 
    } 
} 
1

我有一個解決方案,而不是一個快速的(或相當)的解決方案,但一個解決方案儘管如此:)

rundll32 url.dll,FileProtocolHandler使用與http/s協議(試行rundll32 url.dll,FileProtocolHandler http://www.google.com?q=google)網址時,並通過參數,可以讓你可以設置小型的http服務器(喜歡我猜),以滿足您的幫助文件,並使用

rundll32 url.dll,FileProtocolHandler http://localhost:[helpServerIp]/help/pophelp.html?TAG=callsubflow