0% found this document useful (0 votes)
36 views4 pages

Lab 4

The document describes steps to develop a servlet application that displays a list of DVD items. It involves creating a DVDItem model class, a ListLibraryServlet that retrieves DVD items and generates the response, and configuring the web application by adding servlet mappings and a homepage.

Uploaded by

naderaqistina23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

Lab 4

The document describes steps to develop a servlet application that displays a list of DVD items. It involves creating a DVDItem model class, a ListLibraryServlet that retrieves DVD items and generates the response, and configuring the web application by adding servlet mappings and a homepage.

Uploaded by

naderaqistina23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CSC584 ENTERPRISE PROGRAMMING

LAB 4: SERVLET -1
Lab Activities
Figure below illustrates the use case diagram for the DVD Library application.

1. Developing the View Servlet


In this exercise, you will develop the List library view servlet. This view generates a dynamic response by
displaying the collection of DVDs to the user.

Task 1: Create the DVDItem Model file


The DVDItem model component is a class based on the JavaBeans architecture, which represents a
single DVD’s information.
DVDItem
-title
-year
-genre
+DVDItem(title: String, year: String, genre: String)
+getYear(): String
+getTitle(): String
+getGenre(): String
a) Create the DVDLibrary Web application project with the following characteristic:
Project: DVDLibrary
Location: C:\Users\User\Documents\NetBeansProjects
Folder: C:\Users\User\Documents\NetBeansProjects\DVDLibrary
Server : Personal glassfish
Java EE version: Java EE 7
Contextpath: /DVDLibrary

b) Create a java class with the following characteristic:


Class name: DVDItem
Project : DVDLibrary
Location:Source Package
Package : com.dvd.model

MMR@FSKM2018
CSC584 ENTERPRISE PROGRAMMING

c) Modify the DVDItem class to implement the java.io.Serializable interface

d) Add the following private properties to the DVDItem class and provide a getter method for each
property:
String title
String year
String genre
e) Add a constructor to the DVDItem class with the following parameters
String title
String year
String genre
f) Code the constructor to initialize the fields with the parameter values
g) Compile the DVDItem Class.

Task 2: Write the ListLibraryServlet View Servlet


In this task, you create a ListLibraryServlet to generate an HTML response that display the number of
DVDs in the user collection and their titles.
a) Create a Java Servlet with the following characteristic:
Class name: ListLibraryServlet
Project : DVDLibrary
Location:Source Package
Package : com.dvd.view
Servlet name: ListLibraryServlet
URL Pattern : /list_library.view
Initialization Parameters : None

MMR@FSKM2018
CSC584 ENTERPRISE PROGRAMMING

b) Import the following classes in the ListLibraryServlet class:


java.util.List
java.util.Iterator
java.util.ArrayList
com.dvd.model.DVDItem

c) Within the processrequest method, create a collection of DVDItem objects, each one
representing a DVD in the user’s DVD collection.
d) Use print statements to generate the HTML response described at the beginning of this task.

e) Compile the ListLibraryServlet servlet class.

MMR@FSKM2018
CSC584 ENTERPRISE PROGRAMMING

2. Configuring the Web application

Task 1 : Verify the view servlet configuration


a) Open the web.xml deployment descriptor
b) View the definition and the mapping for the ListlibraryServlet servlet.

Task 2: Create the homepage


a) Create an HTML file with the following characteristic:
Project : DVDLibrary
HTML file name: index
Location:Web Pages

b) Edit the index.html file so that it displays the following text.


Display my DVD Library
c) Edit the index.html file to add a link to the List library page.

d) Open the web.xml deployment descriptor and set index.html as the welcome file.

Task 3: Deploy the web application


a) Build the DVDLibrary web application. Correct any errors you encounter
b) Deploy the DVDLibrary web Application
c) Run the web application project
d) Click the display my DVDLibrary link to display the list of DVDs.

MMR@FSKM2018

You might also like