Exercise 5 : Additional Lab Exercise
Note : This lab is not mandatory, it is there if you would like
to take things further. There is little or no sample code although it is
suggested that you use the code from the initial lab exercise as a starting
point.
Using a entity bean to represent data
Building on the code of the previous additional lab exercises we shall
now introduce entity beans. Entity beans represent data in the database,
we need to write an entity bean which represents the data in our JDBC query.
The central part of the implementation is to define the remote interface
to the bean so that the data from the database can be accessed. The JDBC
code from the Session Bean (originally from the servlet) can be moved to
the ejbLoad method.
Amend the session bean to lookup the home interface of our entity bean
and use that to obtain results equivalent to the original database query.
You'll need an appropriate method in the home interface of the bean which
returns all entries. The servlet can call the session bean as normal and
therefore the servlet and JSP page can remain unchanged.
Extensions
The authentication mechanism mention in earlier lab exercises could be
tied to the information held in the database. One the user has successfully
logged in, a session is created. Only with a valid session can the database
query be executed and the results displayed.
© Steve Ferris 2000