运行java applet后重定向?

时间:2012-04-26 23:20:01

标签: java redirect applet-servlet

我用谷歌搜索但没有得到答案。接近我的目标唯一的事情是在X秒后使用元重定向,如下所示:

<meta http-equiv="refresh" content="5;url=index2.html">

我需要的是php或html代码,用于检测我的java applet是否已在页面上运行,然后重定向到另一个文件地址。

我怎么可能这样做,有人可以如此善良地给我一个示例代码吗? 非常感谢,非常感谢您的时间。

2 个答案:

答案 0 :(得分:3)

如果您想从applet重定向,请编写以下代码:

import java.applet.*;
import java.awt.Graphics;
import java.net.MalformedURLException;
import java.net.URL;

public class AppletExample extends Applet
{

public void init() {

try {
getAppletContext().showDocument(new URL("http://www.google.com"), "_blank");//This is new tab/
getAppletContext().showDocument(new URL("http://www.google.com"), "_parent");//This is in the parent tab/
}
catch (MalformedURLException ex) {
System.out.println(ex.getMessage());
}
}

public void paint( Graphics g ) {

g.drawString("Go Google", 0,100);
}

}

答案 1 :(得分:0)

如果您想要从applet中触发重定向,我会尝试使用showDocument()。它可以像这样使用:

this.getAppletContext().showDocument(URL, "_parent");