Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CSC 584 ENTERPRISE PROGRAMMING

LAB 5: SERVLET -2
Lab Activities
1. Developing the AddDVD form

Task 1: Develop the HTML Form


a) Create an HTML file with the following characteristics:
HTML file name = add_dvd
Project: DVDLibrary
Location: Web Pages
Folder: None

b) Add a form to add_dvd.html that performs a POST request to the URL add_dvd.do
c) Create the form elements to gather the data.

Task 2: Modify the Home Page


a) Open the index.html file
b) Add a link to the Add DVD form in the index.html file

Task 3: Deploy the web application


a) Build the DVDLibrary web application. Correct any errors you encounter
b) Deploy the DVDLibrary web Application

Task 4: Test the AddDVD Form

MMR@FSKM2018
CSC 584 ENTERPRISE PROGRAMMING

2. Developing a controller servlet


Task 1: Develop the controller Servlet

a) Create a Java Servlet with the following characteristic:


i. Class name: AddDVDServlet
ii. Project: DVDLibrary
iii. Location: Source Package
iv. Package:com.dvd.controller
v. Servlet Name: AddDVDServlet
vi. URL pattern:/add_dvd.do
vii. Initialization Parameters: None
b) Within the doPost method, create the DVDItem instance using the parameters in the incoming
request.
c) Use print statement to generate a simple text response, such as SUCCESS

Task 2 : Deploy the web application


1. Build the DVDLibrary web application. Correct any errors you encounter
2. Deploy the DVDLibrary web Application

Task 3: Test the AddDVDServlet


1. Refresh the DVDLibrary web application home page
2. Click the link to add a DVD.
3. Fill in and submit the form

MMR@FSKM2018
CSC 584 ENTERPRISE PROGRAMMING

3. Developing the Success View Servlet


Task 1: Modify the Add DVD Controller Servlet
a) Open the AddDVDServlet class in the com.dvd.controller source package
b) within the doPost method, remove the lines of code that print the SUCCESS message to the
output stream.
c) Store the DVDItem instance created in the request object with the attribute name dvdItem.
d) Perform a dispatch to the URL /success.view

Task 2: Develop the Success View Servlet


a) Create a Java Servlet with the following characteristic:
i. Class name: SuccessServlet
ii. Project: DVDLibrary
iii. Location: Source Package
iv. Package:com.dvd.view
v. Servlet Name: SuccessServlet
vi. URL pattern:/success.view
vii. Initialization Parameters: None

b) Within the processRequest method, retrieve the DVDItem instance from the request object using
the attribute name dvdItem.
c) Use print statements to generate the HTML response, displaying the information in the DVDItem.
d) Include a hypertext link back to the home page in the HTML

MMR@FSKM2018
CSC 584 ENTERPRISE PROGRAMMING

Task 3 : Deploy the web application


a) Build the DVDLibrary web application. Correct any errors you encounter
b) Deploy the DVDLibrary web Application

MMR@FSKM2018
CSC 584 ENTERPRISE PROGRAMMING

4. Developing the Error View Servlet


Task 1 – Modify the Add DVD Controller Servlet
a) Open the AddDVDServlet class in the com.dvd.controller source package
b) Within the doPost method, create a List reference called errors and assign this reference to a new
ArrayList.

c) Perform error checking for each of the request parameters.


d) If you find an error, add a string to the errors list indicating what errors was encountered

e) Modify the section of code in which the dispatch is performed and check the errors list
i. If the errors list is empty, store the DVDItem in the request object and dispatch to the
URL /success.view.
ii. If the errors list is not empty, store the errors list in a request attribute called errorMsgs
and dispatch to the URL /error.view

MMR@FSKM2018
CSC 584 ENTERPRISE PROGRAMMING

Task 2 – Create the Error View Servlet


a) Create the ErrorPageServlet in com.dvd.view
b) The content of the code as follows:

Task 3 – Configure the Error View Servlet


a) Open the web.xml deployment descriptor
b) Define the ErrorPageServlet with the following properties:
i. Servlet Name : ErrorPageServlet
ii. Servlet Class: com.dvd.view.ErrorPageServlet
c) Declare the servlet mapping the ErrorPageServlet servlet with the following properties:
i. Servlet Name : ErrorPageServlet
ii. URL Pattern(s) : /error.view

Task 4 – Deploy the Web Application


a) Build the DVDLibrary web application. Correct any errors you encounter
b) Deploy the DVDLibrary web Application

MMR@FSKM2018

You might also like