使用 Java 处理 URL 方案
有人知道如何用 Java 处理自定义 URL 方案吗?就像当您在浏览器中访问任何 itms:// URL 时,iTunes 都会处理它。
我知道通过编写调用我的 Java 代码的本机代码应用程序可以实现这一点,但我不知道仅使用 Java 是否可以实现这一点。
我可能会使用一些 AWT 代码,并且需要浏览器调用它。
谢谢!
Anybody knows how to handle custom URL schemes with Java? Like when you access any itms:// URL in browser, iTunes will handle it.
I know it's possible by writing native code applications that calls my Java code, but I don't know if it's possible with Java only.
I'll probably use some AWT code and I need it to be called by the browser.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最接近的启动方法是通过 http:// docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html 但这要么执行
open(File f)
或browse(URI)
。也许浏览间接适合您的目的。下一个方法是通过新协议的
Handler
来扩展 URL 协议(例如itms:
)。在网络上搜索java protocol Handler
,因为它依赖于固定的类和包名称,我在这里的解释质量很差。然后您可以将 URL 传递给本地代码。这允许您将这些新 URL 与
java.net.URL
一起使用。The nearest way to launch something would be via http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html but that either does an
open(File f)
orbrowse(URI)
. Maybe browse indirectly works for your purpose.The next approach would be to extend URL's protocols by a
Handler
for a new protocol (likeitms:
). Do a web search forjava protocol Handler
as it relies on fixed class and package names, and an explanation here by me would be of poor quality. Then you could pass the URL to local code.This allows you to use these new URLs with
java.net.URL
.