Article
The JSP Files - Parts 1 to 8: Tagged and Bagged
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 Next
The JSP Files - Part 4: The Red Pill
Applying The Theory
Last time out, we gave you a crash course in the numerous controls structures available to you in JSP - operators, conditional statements, and loops. But there's a big difference between learning theory in a classroom and actually practicing it in the real world - which is why this issue of The JSP Files is devoted to a discussion of how JSP can be used to extract and use data from HTML forms.
Over the next few pages, we're going to show you how JSP can be used to process the data entered into a Web form - everything from simple text boxes to lists and checkboxes - and we're also going to demonstrate how to use array variables in JSP.
The Last Action Hero
HTML forms are typically used to obtain information from visitors to a Web site - things like their name, mailing address, phone number, and the like - and this information is then processed in a variety of different ways. Some sites store it in a database; others email it to the webmaster; and still other simply redirect it to the trash basket. By using JSP to process a form, you can write simple code snippets that accomplish all of these actions.
Let's begin with a simple example.
<html>
<head>
<basefont face="Arial">
</head>
<body>
<center>
<form method="GET" action="matrix.jsp">
<table cellspacing="5" cellpadding="5" border="0">
<tr>
<td>
<font size="-1">Name, rank and serial, number, soldier!</font>
</td> <td align="left"> <input type="text" name="name" size="10">
</td> </tr>
<tr>
<td colspan="2" align="center">
<input type="submit">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
The most critical line in this entire page is the <form> tag:
<form method="GET" action="matrix.jsp">
...
</form>
As you probably already know, the ACTION attribute of the <FORM> tag specifies the name of the server-side script - "matrix.jsp" in this case - that will process the information entered into the form, while the METHOD attribute specifies the manner in which the information will be passed.
Copyright Melonfire, 2000. All rights reserved.