Using the request Object

As you saw in Listing 15.2, the getParameter method in the request object retrieves the values of form variable. The lone argument to getParameter is the name of the form variable as it was defined in the HTML form, and must match the case exactly. In other words, if you called a form variable firstName in the HTML file, you must pass "firstName" to getParameter and not "firstname" or "FIRSTNAME."

If you ask the request object for the value of a form variable that does not exist, it returns null. Note that getParameter always returns a string. If you are expecting a number, you have to convert it yourself.

Note

There's a difference between a form variable that is empty and a form variable that does not exist. The value ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.