Jython:在浏览器中打开URL(无需导入Python库) [英] Jython: Open URL in browser (without importing Python libraries)

查看:81
本文介绍了Jython:在浏览器中打开URL(无需导入Python库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maximo 7.6.1.1:

Maximo 7.6.1.1:

我想使用Jython在浏览器中打开一个URL(在Windows 10中).

Using Jython, I want to open a URL in a browser (in Windows 10).

我找到了 Java示例:

import java.awt.Desktop;
import java.net.URI;

if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
    Desktop.getDesktop().browse(new URI("http://www.example.com"));
}

我已经尝试将其转换为Jython:

And I've attempted to convert it to Jython:

from java.awt import Desktop
from java.net import URI

desktop = Desktop.getDesktop()
uri = URI("http://google.com/#q=wonum1%2Cwonum2%2Cwonum3")
desktop.browse(uri)

Jython编译成功时,打开浏览器.

While the Jython does compile successfully, it does not open the browser.

如何使用Jython在浏览器中打开URL?

推荐答案

简短答案

你不能."或者,更准确地说,这不值得付出努力/冒险."

The short answer

"You can't." Or, more accurately, "It's probably not worth the effort / risk."

根据以前的经验,使用VB编写CGI(我不建议这样做),我猜想将您问题中的代码放入自动化脚本中可能会导致浏览器会话在服务器上启动,而您的脚本所在的位置跑.自20年前的VB以来,情况可能已经发生了变化,但我仍然很想检查一下.

From previous experience, using VB to write CGI (which I do NOT recommend), I would guess that putting the code from your question in an automation script might cause a browser session to get launched on the server, where your script was run. Things may have changed since those VB days, 20+ years ago, but I would still be tempted to check.

@Milton我认为是正确的,但是使用Maximo,实际上会更加复杂.这是因为当他说您可以让[脚本]返回响应"时,该响应将从服务器端的业务逻辑层返回到服务器端的UI层,然后必须将其返回给您必须大C"浏览器才能自定义Maximo,以期望得到该响应并知道如何处理.

@Milton was on the right track, I think, but with Maximo it would actually be a little more complicated. This is because when he said, "You could have [the script] return a response", that response would be returned from the business logic layer on the server side to the UI layer on the server side which would then have to return it to the browser, which you would have had to "big C" customize Maximo to expect that response and know what to do with it.

您可能会从脚本中返回错误,并在消息中包含URL.或使用自动脚本+有条件的用户界面+在上下文中启动+非持久属性混合来显示链接以供用户单击.

You could maybe return an error from your script, and have the message include a URL. Or use an Autoscript + Conditional UI + Launch in Context + Nonpersistent Attribute mix to expose a link for the user to click.

这篇关于Jython:在浏览器中打开URL(无需导入Python库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆