Java Reference
In-Depth Information
Figure 22-1: Output of ManageYacht client
By clicking the hyperlink marked "View Session," you should be able to view the session associated
with this yacht (that is, whether it is in an active cruise operation, the current status such as velocity and
passenger list, and so on). From the code in Listing 22-5 , you can see that clicking the View Session
hyperlink sends a request to another JSP client: YachtSessionjManager. jsp , as shown here:
<a href=YachtSessionManager.jsp?YachtPK=<%= (String)yacht.getPrimaryKey() %>
&Action=View>View Session</a>
The code for YachtSessionjManager.jsp is not provided here, and I do it on purpose. By now you
should be able to write your own client to use these EJBs to meet your own needs. You have learned all
the skills you need to access these EJBs from your own client. Do this as an exercise!
Your yacht-session-management client should allow a user to check whether a cruise session is active.
If no active session is associated with the yacht the user has selected, the user should be prompt to
create a session. Once a cruise session is created (or retrieved), the user should be able to operate the
cruising yacht. That means the user is able to start, stop, accelerate and decelerate the yacht, check the
yacht status, drop off passengers, pick up members, and so on.
Because only members can come on board, you do need the help of MemberEJB to implement the
preceding functionality. You can write a JSP client, a Swing client, or a stand-along client. If you decide
to use the JSP client, you may be able to take advantage of the functionality provided by the
HttpSession interface. For example, once a YachtSessionEJB instance session is created, you can
save it to HttpSession as follows:
session.setAttribute(yachtPrimaryKey, theYachtSession);
When a user wants to view the YachtSessionEJB instance for a specific yacht, you just need to
retrieve it as follows:
myYachtSession = (YachtSession)session.getAttribute(yachtPrimaryKey);
When an active session is destroyed (that is, the cruise is completed), you remove the
YachtSessionEJB instance as follows:
session.removeAttribute(yachtPrimaryKey);
The session.removeAttribute(yachtPrimaryKey) method is called in the
YachtManager.jsp shown in Listing 22-5 . When a yacht is removed, its associated YachtSession
is also removed.
To give you more hints, you may write a JSP client that provides a user interface similar to what is
shown in Figure 22-2 . The yacht name and current status are shown on the top of the screen. A user
can start and stop the yacht. He or she can also speed up or slow down the yacht by a certain velocity.
Search WWH ::




Custom Search