Chapter 14 - Using JavaBeans
This application contains the following components:
1. Section 14.1.1, Listing 14.1: /WEB-INF/classes/AddressBean.class
2. Section 14.1.2, Listing 14.2: /addressForm.html
3. Section 14.1.2 : /address.jsp
4. Section 14.2.3, Listing 14.4: /addressDisplay.jsp
5. Section 14.1.3, Listing 14.3: /beanSaver.jsp
Click on this link to see the first four components in action:
addressForm.html
How it works
1. When you click the above URL, it gets the addressForm.html page.
2. This page contains an HTML form with its action
attribute pointing
to address.jsp.
3. address.jsp creates an instance of type AddressBean and sets its properties using the form data.
4. It then puts the
bean into the session and forwards the request to addressDisplay.jsp.
5. addressDisplay.jsp gets the AddressBean instance from the session, and prints its values.
Using serialized beans
Click on the link below to see the fifth component in action.
beanSaver.jsp?name=john&city=Ardsley&state=NY
We have already created the directory structure /WEB-INF/classes/businessData/visitorAddresses/ in chapter14 web application. When you click the above link, it will create a serialized file named john.ser under the
/WEB-INF/classes/businessData/visitorAddresses/" directory. You can then use this bean using the beanName attribute of the <jsp:useBean> action.
Open the source files, modify the code, play around with it, and practice the different ways to use
the useBean, setProperty, and getProperty actions to get familiar with them.