A Bit About Processing Forms

 

Introduction.  Now we get to one of the most important ways to interact with users.  The next page will do a little survey of HTML form syntax and work an example.  This page will discuss a bit about how forms can be processed using JSP.

We need some HTML in order for the user to enter some information.  The basis of these web based user interactions will be done through HTML using the <FORM> </FORM> tag pair.  But after the user enters the appropriate information we need to do things like

  • validate inputs
  • retrieve validated inputs
  • process inputs

While there are many other things we will likely want to do with forms there are two main ways that data from forms can get to processed.

In general the <FORM> tag makes use of the following syntax

<FORM   METHOD=______   ACTION="somePage.jsp">

 

where the METHOD can be set to either GET or POST.  We will focus on <FORM> tags where

<FORM   METHOD=POST   ACTION="some_page.jsp">

since this has several advantages for what we'll be developing.  "some_page.jsp" is the name of the form processing script page that we defined in the last course page.

If we were to use GET as the METHOD, we would be relying on working with QueryStrings.  While certainly not insurmountable, they have their disadvantages such as they cannot become longer than 255 characters, for every value you want to get from the user the computer needs to append the variable name and inputted value to the QueryString, and the QueryString shows up in the URL for the form processing script.  Rather than try to talk about all of these issues in detail, we will just focus on using POST as the METHOD.

When working with forms and JSP it is most typical to have two major pages involved.

 

Page Type Description
Form Page Usually an HTML page that contains a form where the user can enter information.
Processing Page In our setting it will almost surely be a JSP page that obtains the data entered by the user, probably validates it to some extent and then processes it.

 

It is entirely possible that the form page and the processing page will be the same.  This requires a bit more cleverness in nesting the logic in the JSP and positioning the HTML for the form.  But it is often very useful.  However, we will make all of our initial examples work with a form page and a processing page that are distinct.

There isn't much more to say at this level.