如何在Windows 7中将URL参数从Java传递到本地HTML文件?

我迫切需要你在解决Windows-7问题方面的专业知识。

场景:我有一个基于框架的帮助包,设置用于上下文相关的帮助调用。 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 file:// C:\ Program Files \ App System \ App-Editor-8.0.1 \ help \ pophelp.html?TAG = callsubflow

结果: ?TAG =未传递callsubflow。

使用Desktop.getDesktop()的新代码。browse() –

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。

任何援助将不胜感激!

我真的不知道为什么Windows会删除本地文件的参数。 正如评论中所提到的,这种接缝对安全性是一种奇怪的限制。 但我曾经遇到类似的问题,我找到了适合这种情况的解决方法。
只需创建一个本地临时HTML文件(不带参数),即可将您重定向到所需的文件(带参数)。
看看这两种方法:

 // creates w3c conform redirect HTML page public String createRedirectPage(String url){ return "" + "" + "" + "" + "Page Redirection" + "" + "If you are not redirected automatically, follow the link"; } // 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"))); } } 

我有一个解决方案,而不是一个快速(或漂亮)的解决方案,但仍然是一个解决方案:)

rundll32 url.dll,FileProtocolHandler在使用带http/s协议的URL时传递params(尝试rundll32 url.dll,FileProtocolHandler http://www.google.com?q=google ),这样就可以设置小型http服务器(如Jetty)我猜)提供帮助文件并使用它们显示

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