Click to See Complete Forum and Search --> : going to URL from an Applet


AD321
02-15-2005, 11:21 AM
Hi, basically what i'm attempting to do is pass a URL string using java script to an applet, and then on the applet the string is displayed and the user clicks on a 'go to url' button and is taken to that address, currently i can get the applet to print the URL, but i clueless as to how i can go about re-directing the user to the url...if anyone can help that would be mch appriciated, i have posted my code below, thanking you in advance,

-Arthur



import java.awt.*;
import java.applet.*;

public class getname extends Applet
{

String URL;

private Button clickButton;
public void init()
{
clickButton = new Button("Go to URL");
add(clickButton);

setBackground(Color.white);
}

public void paint(Graphics g)
{

g.drawString("You have Entered" + this.URL, 15, 15);
}



}

Khalid Ali
02-16-2005, 11:29 PM
there is requestDispathcer()
and there is a response.reDirect() methods

Look in the APIs for
HttpServletResponse and
HttpServletRequest

ray326
02-17-2005, 10:29 AM
But you couldn't use those in an applet could you?

Khalid Ali
02-17-2005, 03:10 PM
I think here is a code snippet that will work I found browsing the internet

URL url = null;
try {
url = new URL(getAppletSource(),DocumentName);
}catch (MalformedURLException e){
System.err.println(“Malformed URL: “ + DocumentName);
}
if (url != null){
getAppletContext().showDocument(url, WindowName);
}