CSCI399
Autumn Session, 2009

Assignment 4: Java Servlets

You should complete exercise 4 before starting this assignment.


Aim

This assignment aims to give you basic skills in the deployment of a Java "web application" in an application server.

Objectives

The objectives are for you to:

In assignment 4, you are to use the traditional approach of application defined "beans" and use of JDBC. In assignment 5, you will meet the newer "Java Persistence Architecture" model where much of the code for data persistence is generated entirely automatically.


Deployment

We will be using the combination of Netbeans 6 and Sun's AppServer 9 as installed on the Ubuntu Linux machines in the laboratory.

AppServer 9 ("glassfish v2") is a composite server with a "Web" server and an "EJB" server component. The Web server is a modified version of Tomcat. (The Ubuntu installation also has a copy of the standard Tomcat 6, but in assignments 4 and 5 you should deploy onto the AppServer.)

Netbeans greatly simplifies deployment as compared to older style development environments. You create your "web application" (webapp) with its servlets, beans, static HTML pages, and libraries and simply "build" then "deploy". You can then aim a browser at your webapp on your server. (You can use System.out.println tracer statements in servlet code - such outputs appear in the server log which you can read.)

Netbeans has a "wizard" that helps create the web.xml deployment files needed for your servlets. While you can view (and even edit) the XML yourself, it is much easier to use the dialogs in this wizard.

You will need to define database connections, and also a set of "users" for your applications. The users will be assigned roles that will be mapped to application specific roles that determine access privileges. You will also need to add libraries to the default set supplied by Netbeans. These aspects of the assignment should be covered in the associated preliminary exercise.


Tasks

RentADump

Overview

For reasons best known to themselves, the RentADump property rental agency has decided not to go with domain.com.au but instead create their own web-site that presents the properties that they have listed for lease.

RentADump requires the development of a web-application that:

  1. Works with an Oracle database of property records - each record describing a property currently available for lease, or one that will soon be available for lease.
  2. Allows any Internet user to browse for properties - the user will have some facilities for defining the type, location, and price range of properties of interest.
    Simple search form
    A search request will result in a tabular listing of suitable properties.
    Retrieved properties
    The entries in these listings will each include a link that will display more detailed information including photographs of the exterior and interior of the property.
    Detailed propterty description
    The detailed display page will also include a link to Google maps; use of this link should result in Google displaying the map (and associated things like a street view) in a separately opened window.
    Google map shown
  3. An employee of the RentADump agency can login from any Internet terminal and add new records or amend existing records. The data uploaded from the form are to be processed by a servlet that will create a new record in the data table and respond with a simple acknowledgement page (that should include the property identifier - a key value auto-generated by the database). A simplified view of an appropriate form is: Data entry form
  4. An approved employee of the RentaDump agency can upload image data. A simple data entry form is used that has fields for property identifier, interior/exterior view selection, and input file field.

Notes

  1. Database

    The following table definitions are suggested for use with Oracle; you may wish to adapt them slightly:

    drop table photos;
    drop table properties;
    drop sequence photoseq;
    drop sequence propertyseq;
    commit;
    
    create sequence photoseq increment by 1 start with 1;
    create sequence propertyseq increment by 1 start with 1;
    
    create table properties (
        propertyid number primary key,
        streetaddress varchar(48),
        suburb varchar(32),
        postcode number,
        accomtype varchar(16),
        beds    number,
        baths   number,
        cars    number,
        maxres  number,
        avail   date,
        weeklyrent number,
        furnish varchar(16),
        description clob,
        constraint prop_accomtype
            check (accomtype in ('House', 'Townhouse', 'Apartment')),
        constraint prop_furnish
            check (furnish in ('Furnished', 'Part furnished', 'Unfurnished'))
    );
    
    create table photos (
        photoid number primary key,
        propid number,
        phototype varchar(4),
        photocode varchar(4),
        photodata blob,
        constraint photo_type
            check (phototype in ('Int', 'Ext')),
        constraint photocode_type
            check (photocode in ('GIF', 'JPG', 'PNG')),
        constraint photo_prop
            foreign key(propid)
                references properties(propertyid)
    );
    
    
  2. Application users
    You will need to define some users and two kinds of user-role. The process is illustrated in exercise 4.
  3. File upload
    You will use the fileupload components from the Apache commons project. This requires two ".jar" files to be added to your project). The relevant files (fileupload.jar and io.jar) can be found in the /share/cs-pub/399/A4 directory. The Apache/Jakarta/Commons/Fileupload site contains a description of how to use this package (there is also a tutorial example at the www.onjava.com website - but this example relates to an earlier version of the fileupload package and uses functions that are now deprecated).
  4. Images
    Images are to be stored as "blobs" in the database. Your Java code treats them as byte[]. The Apache file upload API has a method for getting a byte array for an uploaded file. The JDBC API includes getBytes etc for accessing Blob data.
    The detailed description page contains links for the images - these should reference a servlet that simply returns the image bytes in an HTTP response with a header setting the content type to image/gif or image/png etc. This little helper servlet loads the image data from the data table and writes the bytes to the binary output stream associated with the HTTP response.
  5. A4 webapp directory
    This should contain the HTML pages used for the "login page", and the "error page". The loginpage and errorpage should be customized versions the standard ones (with suitable "RentADump employee login" banners etc).
  6. Database access
    You can follow the simple lecture examples and use a DBInfo helper class to establish a database connection.
  7. Compilation of servlets
    This can be a bit painful if done manually, but Netbeans automates everything and arranges for compilation and run time class paths to be correct!
  8. Libraries
    Your project's libraries will include the Oracle ojdbc14.jar file and the two Apache commons .jar files.
  9. Google maps
    It is easy to link to Google maps - see map usage details.
  10. HTML pages
    You will need static HTML pages for the "login page" and "login error page". You may use HTML pages for the forms used for searching, adding rental properties, and adding photos - alternatively you could have these pages generated dynamically via the doGet method of the corresponding servlet.
  11. Response pages
    The response pages for successful upload of property details and photos can be very simple acknowledgement pages; but it is probably better if they just return the same form page so allowing for further inputs (the page should contain an acknowledgement that the last input has been processed successfully).
    The response pages for search requests should be well styled. The page showing all details of the property should group and show exterior views (if any) before interior views.

Submission

The due date for submission will be announced in lectures; provisionally set for May 22nd.

As with previous assignments, you will submit a report on your work for assessment. This should be a word processed document converted to PDF format; it will need to include some screenshots of your work.

Each servlet should be presented in a separate section. You should provide a listing of the servlet code and of any supporting classes that you defined. A source listing of the wizard generated web.xml file should be included.

There should be screen shots illustrating your forms and responses and evidence to prove that access controls are applied. Selective listings of database tables might also be used as evidence for a working application.

You should use stylesheets to set an overall style for your site, and should aim to create something more attractive than my demonstration pages illustrated above.

For this assignment you submit your work using the command:

turnin -c csci399 -a 4 A4.pdf

As always, late submissions are possible for a few extra days; in this case they will take the form:

turnin -c csci399 -a 4late A4.pdf

Marking

  1. 1 mark overall quality and appearance of report.
  2. 1 mark quality and appearance of web site
  3. 4 marks for all parts working as adequately documented through submitted evidence
  4. 4 marks for Java code of these simple servlets and beans.