java 小程序不响应 webkit 浏览器中的重绘请求
我目前正在编写一个小型 Java 小程序,以与浏览器无关的方式解决我们公司内部网中的特定问题。这过去是通过 ActiveX 来完成的,但我们希望让人们远离 IE。该代码对于公众使用显然不安全,但在受控情况下很有用。本质上,我希望用户能够单击其中的链接,并根据 AJAX 调用返回的数据打开安装在本地计算机上的应用程序。这是一个已签名的 Java 小程序,并且证书已在本地计算机上被接受。
目前,这在 IE 和 Opera 中完美运行,但在 Chrome 和 Safari 中失败。看来 repaint() 方法实际上并没有导致重新绘制,这是我正在努力解决的问题。这是小程序代码:
import java.applet.Applet;
import java.awt.Graphics;
import java.util.*;
public class OdehAppLauncher extends Applet {
private ArrayList<String> toRun = null;
public void paint(Graphics g) {
System.out.println("-----painting");
try {
if (toRun != null) {
new ProcessBuilder(toRun).start();
toRun = null;
}
} catch (Exception e) {
System.out.println("-----Exception e = " + e);
e.printStackTrace();
}
}
public void runApp(String appName, String args) {
System.out.println("-----running app: " + appName);
toRun = new ArrayList<String>(2);
toRun.add(appName);
toRun.add(args);
System.out.println("-----triggering a repaint...");
repaint();
}
}
以下是调用 runApp 方法时四个测试浏览器中每个浏览器的 Java 控制台的最后几行:
IE 9(测试版)- 有效:
基本:小程序已启动
基本:告诉客户小程序已启动
-----绘画
-----运行应用程序:notepad.exe
-----触发重绘...
-----绘画
Safari 5.0.2 (7533.18.5) - 失败
liveconnect:JavaScript:默认安全策略=
-----运行应用程序:notepad.exe
-----触发重绘...
Opera 10.62 - 有效
基本:小程序已启动
基本:告诉客户小程序已启动
-----绘画
-----绘画
-----绘画
-----运行应用程序:notepad.exe
-----触发重绘...
-----绘画
Chrome 6.0.472.63 - 失败
基本:小程序已启动
基本:告诉客户小程序已启动
-----运行应用程序:notepad.exe
-----触发重绘...
如果您能想到导致行为不一致的任何原因(或者一般情况下更好的方法),请告诉我。我还应该指出,我尝试直接从 runApp 调用启动进程,但普遍失败。
I currently have a tiny Java applet I'm writing to solve a specific problem in our company intranet in a browser neutral way. This used to be accomplished with ActiveX but we'd like to let people move away from IE. The code is obviously unsafe for public consumption, but it's useful under controlled circumstances. Essentially I want the user to be able to click a link in their and open an application installed on the local machine based on data returned from an AJAX call. This is a signed Java applet and the certificate has been accepted on the local machine.
Currently this works perfectly in IE and Opera, but it fails in Chrome and Safari. It appears that the repaint() method doesn't actually cause a repaint, which I am struggling with. Here's the applet code:
import java.applet.Applet;
import java.awt.Graphics;
import java.util.*;
public class OdehAppLauncher extends Applet {
private ArrayList<String> toRun = null;
public void paint(Graphics g) {
System.out.println("-----painting");
try {
if (toRun != null) {
new ProcessBuilder(toRun).start();
toRun = null;
}
} catch (Exception e) {
System.out.println("-----Exception e = " + e);
e.printStackTrace();
}
}
public void runApp(String appName, String args) {
System.out.println("-----running app: " + appName);
toRun = new ArrayList<String>(2);
toRun.add(appName);
toRun.add(args);
System.out.println("-----triggering a repaint...");
repaint();
}
}
Here are the last few lines of the Java Console for each of the four tested browsers when the runApp method is called:
IE 9 (beta) - works:
basic: Applet started
basic: Told clients applet is started
-----painting
-----running app: notepad.exe
-----triggering a repaint...
-----painting
Safari 5.0.2 (7533.18.5) - fails
liveconnect: JavaScript: default security policy =
-----running app: notepad.exe
-----triggering a repaint...
Opera 10.62 - works
basic: Applet started
basic: Told clients applet is started
-----painting
-----painting
-----painting
-----running app: notepad.exe
-----triggering a repaint...
-----painting
Chrome 6.0.472.63 - fails
basic: Applet started
basic: Told clients applet is started
-----running app: notepad.exe
-----triggering a repaint...
Please let me know if you can think of any reason why this isn't behaving consistently (or a better way to do this in general). I should also point out that I've tried just launching the process directly from the runApp call, but that fails universally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这个链接给出了一些提示。例如:
您可能想检查小程序是否可见,最近是否有绘画,以及是否调用了 update(Graphics)...
Maybe this link gives a few hints. For instance:
You might want to check if the applet is visible, if there has been a paint recently, and if update(Graphics) is called...