to the main page about the tutorial  INTERACTIVE WEB SERVICES WITH JAVA back up next

HTML Forms

Users send information to servers via forms:

The Poll Service

Who wins the World Cup 2006?
Please enter your email address:

HTML source:
<h3>The Poll Service</h3>
<form action="http://freewig.brics.dk/users/laudrup/soccer.jsp" method="post">
Who wins the World Cup 2006?
<select name="bet">
<option value="fr">France!</option>
<option selected value="dk">Denmark!</option>
<option value="other country">someone else?</option>
</select><br>
Please enter your email address: <input type="text" name="email"><br>
<input type="submit" name="Submit" value="Go!">
</form>

The browser collects the reply in a query string:
bet=other+country&email=john.doe%40notmail.com&Submit=Go%21

Values are URL-encoded: space becomes +, non-alphanumeric chars become %hexcode - assuming enctype="application/x-www-form-urlencoded" (the default)

GET vs. POST?

Uploading files requires POST and a different encoding of form data:
<form method="post" enctype="multipart/form-data" ...>
<input type="file" ...>

The response then contains:

back COPYRIGHT © 2002-2003 ANDERS MØLLER & MICHAEL I. SCHWARTZBACH next