我们的内部 Java 应用程序在不同时间启动各种 http URL,包括网页、MS Word 文档、MS Excel 文档、PDF 文件等的 URL。
在 50 多台机器上,URL 启动工作正常,正确的应用程序可以正确打开给定的页面/文档。然而,在一台讨厌的机器上,Adobe Acrobat 试图打开每个 URL(无论目标是否是 pdf),并且失败(即使是 pdf 文档):
There was an error opening this document. The filename, directory name, or volume label syntax is incorrect.
启动 URL 的代码是:
URL url = new URL("http://www.example.com");
BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
boolean worked = bs.showDocument(url);
调用后 worked
变量为真。
其他可能有帮助的要点:
- 应用程序在 Java Web-Start 中运行。
- 在同一台机器上运行的小程序能够使用
AppletContext.showDocument()
正确打开 URL - 在 Windows“运行...”对话框中输入 URL 可正确启动 URL。
- 我们已经重新安装了 JRE 和 Adobe Acrobat。
提前感谢您提供的任何建议/帮助。
更新:
以下调试代码产生以下输出:
String[] services = ServiceManager.getServiceNames();
if(services!=null) {
for(int i=0;i<services.length;i++) {
System.out.println("Available Service: "+services[i]);
}
}
BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
System.out.println(url);
System.out.println(bs);
System.out.println("bs.getCodeBase():"+bs.getCodeBase());
System.out.println("bs.isOffline():"+bs.isOffline());
System.out.println("bs.isWebBrowserSupported():"+bs.isWebBrowserSupported());
boolean worked = bs.showDocument(url);
System.out.println("bs.showDocument:"+worked);
} catch(UnavailableServiceException ue) {
System.out.println("UnavailableServiceException thrown");
ue.printStackTrace();
}
Available Service: javax.jnlp.BasicService
Available Service: javax.jnlp.FileOpenService
Available Service: javax.jnlp.FileSaveService
Available Service: javax.jnlp.DownloadService
Available Service: javax.jnlp.ClipboardService
Available Service: javax.jnlp.PersistenceService
Available Service: javax.jnlp.PrintService
Available Service: javax.jnlp.ExtendedService
Available Service: javax.jnlp.SingleInstanceService
http://<snip>
com.sun.jnlp.BasicServiceImpl@bbb8b5
bs.getCodeBase():http://xxx.xxxxxx.com:8080/
bs.isOffline():false
bs.isWebBrowserSupported():true
bs.showDocument:true
最佳答案
你解决这个问题了吗?如果没有,您可以尝试以下方法吗?
FileOpenService fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
关于java - Adobe Acrobat 在 java 中拦截调用 BasicService.showDocument() 的每个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4783518/