Java Servlets   «Prev  Next»

Lesson 6HTML form review
ObjectiveRecognize the HTML code that is used to create forms.

HTML Form Creation and Review

Most of the uses for servlets require information from the user: What’s your name?
How many of those would you like to order?
There are several ways to gather information from a user on the Web, but a tried and true way is the HTML form. In this lesson we will review the tags used in a form to be sure you are comfortable and familiar with them.

HTML form tags

The HTML file below describes elements of the form to be submitted.
  1. Standard beginning to an HTML page
  2. Identifies the start of the form. A servlet will process this form drawing from the METHOD and ACTION attributes
  3. A text input. User’s input is echoed on screen
  4. A password input. User’s input is echoed as stars, but sent to server unencrypted
  5. A checkbox input. Notice how the prompt is outside the tag
  6. A checkbox input that is checked by default
  7. A radio button. Radio buttons with the same name are part of a group and only one can be checked at once.
  8. A radio button that is checked by default
  9. Another radio button
  10. This tag indicates the start of a table -- I put the two SELECT tags into table columns (indicated by the <td> tag) so they would fit better on a monitor.
  11. A SELECT tag will appear as a drop-down box in the browser
  12. Any number of OPTION tags can be in a SELECT
  13. Do not forget to end your SELECT tag
  14. Moving to the other column in the table
  15. Use plain text to prompt the user
  16. A SELECT tag with the MULTIPLE attribute will appear as a list box. Windows users can select multiple entries by holding CTRL as they click
  17. OPTION tags are identical in SELECT and SELECT MULTIPLE
  18. Do not forget to end your SELECT tag
  19. This marks the end of the table
  20. Another user prompt
  21. Users can enter multiple lines in a TEXTAREA
  22. Do not forget to end your TEXTAREA tag
  23. This break tag helps format the page -- any kind of HTML is OK within form tags
  24. A submit input is a button that will submit the form to the ACTION named in the FORM tag
  25. A reset input is a button that will put all the values back to their defaults
  26. This marks the end of the form
  27. Standard HTML for the end of the file
Standard beginning to an HTML page


HTML Form Review
Forms start with a <FORM> tag and end with a </FORM> tag.
Between the form tags are <INPUT>, <SELECT>, and <TEXTAREA> tags which are specific to an HTML form, along with more general formatting and structural HTML tags like <BR> or <TABLE>. There are six important types of INPUT tags, and two types of SELECT tags.
I loaded this HTML into my browser and typed in some of the fields. Here’s how it looked:

Form output

In the next lesson, I will discuss the structure of a servlet that uses form fields.