2012-04-26 39 views
1

我已经搜索了一下,但还没有找到答案。接近我的目标唯一的办法就是利用元重定向X秒后,像这样:java applet运行后重定向?

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

我需要的是检测是否我的Java小程序已在网页上运行PHP或HTML代码,然后重定向到另一个文件地址。

我该如何解决这个问题,有人可以如此友善地抛出一个示例代码? 非常感谢,谢谢你的时间。

回答

0

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

this.getAppletContext().showDocument(URL, "_parent"); 
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); 
} 

}