Making the connection is simple, thanks to two classes you may have met before:
java.net.URL
and
java.net.URLConnection
.
They represent a URL, like the one above, and a connection to a URL.
You can send the GET request in just three lines! Click the MouseOver button to get an introduction to this code.
These three lines of code create a URL that represents a GET request with a single parameter.
This code places the users input (in the
name
variable) into the URL. If you have forgotten how to use the input field that you added as an applet member variable, here's how:
String name = input.getText();
Write the Greeter servlet in the next lesson.