Download Java booking system - School of Computing
Transcript
Note how all of the transition paths in Figure 25; State Chart B, eventually lead
back to the 'initialisation' state. This state is used to fully update all the
information such as the special offers available and outlets that are open, with
information from the EJBs. The reason this is necessary lies in the stateless nature
of the HTTP protocol. Since there is no notion of a continuous connection
between the client and the server, data that is displayed on the users screen is
immediately out of date, i.e. it dies not automatically change when the
information in the database is altered. Therefore it must be refreshed at regular
intervals in order to represent the data with a reasonable level of accuracy.
Additionally, when a user submits a booking confirmation, the system must first
check to see if the booking has not been taken by another user in the time that has
passed since it was first offered. This is shown on the above diagram, by the
'booking gone' state that follows a fail transition from the 'check availability' state.
The Web Site user interface relies upon customer interaction to move the system
back to the initialisation state. This system works fine since it is not vital that the
information is updated regularly. The staff user interface has a greater need for
up-to-date information so a different technique has been employed. A few lines of
JavaScript code ensure that the information that is displayed on the main booking
screen is updated every 60 seconds. It does this by automatically refreshing the
page after it has been held in the browser for 60 seconds. A timeout mechanism
supplied by the JavaScript language was used, and this is shown in the code
below.
<script language="JavaScript">
<!-var refresh = setTimeout("document.forms[0].submit()",60000);
//-->
</script>
The script is executed as soon as the page is read into the browser, which begins
the countdown with the 6000 millisecond value. This is decremented in real-time
until it reaches zero, then the form on the page (forms[0]) is automatically
submitted by the browser. The form is sent to the StaffInitialisationServlet, which
obtains up to date information from the EJBs and returns this to the servlet, in turn
this is passed back to the JSP page used to display the booking information (back
to the starting point effectively).
5.4.2
Web Application Archive & Error Handling
In the Servlet 2.2 specification [28] Sun Microsystems define a special way of
packaging up a Web application, called the Web Application Archive (WAR).
This provides a way to put all the servlets, JSP pages, Java classes, HTML pages,
and images into one single compressed package, that can be deployed as a
complete application to a server. The sample application has been packaged in
this manner. Along with all of the application files. There is an XML deployment
descriptor that is read by the application server when the package is deployed and
contains properties that must be associated with the application. When it is
deployed, the application server will treat the Web application as an individual
application, with properties and system variables assigned to it from the
54