使用 Java 处理 URL 方案

发布于 2024-12-29 20:02:14 字数 192 浏览 4 评论 0原文

有人知道如何用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟柳画桥 2025-01-05 20:02:14

最接近的启动方法是通过 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) or browse(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 (like itms:). Do a web search for java 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文