Capturing Parameter Values Using a Bean
As you may remember from Chapter 6, a bean is often used as a container for data, created by some server process and used in a JSP page to display the data. But a bean can also be used to capture user input. The captured data can then be processed by the bean itself or used as input to some other server component (e.g., a component that stores the data in a database or picks an appropriate banner ad to display).
To capture the user input from the example form, I have implemented a
bean named
com.ora.jsp.beans.userinfo.UserInfoBean
,
with the properties described in Table 8-4.
Property name |
Java type |
Access |
Description |
userName |
|
Read-write |
The user’s full name |
birthDate |
|
Read-write |
The user’s birth date in the format
|
emailAddr |
|
Read-write |
The user’s email address in the format
|
gender |
|
Read-write |
The user’s gender ( |
luckyNumber |
|
Read-write |
The user’s lucky number (between 1 and 100) |
food |
|
Read/write |
The user’s favorite food (any combination of
|
As shown in the “Access” column in Table 8-4, all properties are read/write, meaning that, in addition to using the bean’s properties to generate output, the property values can be set based on user input.
Example 8-4 shows the last part of a JSP page that uses the bean to capture the user input ...
Get JavaServer Pages, 3rd 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.