The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

This e-book contains laboratory activity related to the web development technology by using a Java Programming language. This e-book is a starting point for the students who just started to learn and to understand the web application development by using Java Programming language. With this e-book, students will explore the foundation of web application development by using Java Programming language and learn how Java can be manipulated to achieve final expected results.

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by thariq9694, 2022-08-10 04:19:15

INTRODUCTION OF WEB DEVELOPMENT TECHNOLOGY (WORKBOOK ACTIVITY)

This e-book contains laboratory activity related to the web development technology by using a Java Programming language. This e-book is a starting point for the students who just started to learn and to understand the web application development by using Java Programming language. With this e-book, students will explore the foundation of web application development by using Java Programming language and learn how Java can be manipulated to achieve final expected results.

Keywords: Java,Web Application,servlet

WEIBNTDREODVUECLTOIOPNMOEFNT
TECHNOLOGY

WORKBOOK ACTIVITY

MUHAMMAD THARIQ BIN ABDUL RAZAK, MUHAMMAD FADLI BIN SETOPA
AND MOHD ZUHAIR SHAHIRAN BIN MUHAMMAD NAJIB

INTRODUCTION OF WEB
DEVELOPMENT TECHNOLOGY

WORKBOOK ACTIVITY

Authors:
MUHAMMAD THARIQ BIN ABDUL RAZAK,

MUHAMMAD FADLI BIN SETOPA,
MOHD ZUHAIR SHAHIRAN BIN MUHAMMAD NAJIB

TERBITAN
POLITEKNIK MUKAH,KM 7.5 JALAN OYA, 96400 MUKAH,

SARAWAK.

I

COPYRIGHT
DECLARATION
INTRODUCTION OF WEB DEVELOPMENT TECHNOLOGY
(WORKBOOK ACTIVITY)

Published by POLITEKNIK MUKAH

KM 7.5 Jalan Oya,
96400 Mukah,
Sarawak
Tel : +6084-874 001
Fax : +6084-874 005
Website : https://www.pmu.edu.my/

Copyright © 2022

All right reserved. No part of this publication can be reproduced,
stored in retrieval system or transmitted in any forms or by any
means, electronic or mechanical including photocopying, recording or
otherwise without the prior permission of the copyright owner.

Cover by: Muhammad Thariq bin Abdul Razak

Perpustakaan Negara Malaysia

Authors:
Muhammad Thariq bin Abdul Razak
Muhammad Fadli bin Setopa,
Mohd Zuhair Shahiran bin Muhammad Najib

E-ISBN 978-967-2097-52-5

INTRODUCTION OF WEB DEVELOPMENT TECHNOLOGY
WORKBOOK ACTIVITY

II

ACKNOWLEDGEMENT

First and foremost, we would like to praise and thank Allah S.W.T, the
Almighty for giving us the strength and because of His blessing, we
are able to complete this e-Book Introduction of Web Development
Technology (Workbook Activity). The success of the development of
this e-book were possibly by the guidelines and support from the
family and also friends. It require a lot of efforts and times from each
individual involved in this e-book development and we would like to
express our gratitude to them. Other than that we would like to
acknowledge with thanks to Aisyah Suhailla binti Hj. Jili and Suhaimi
bin Sibir for granting us an opportunity to develop and designed this
e-book project and providing us with guidelines and support. Finally,
we would wish the readers to enjoy reading this e-book and we do
apologize for any omissions and errors. We hope that this e-book will
be beneficial to all, especially to the Polytechnics students and
Polytechnics lecturer so that they can have clear view dan basic
understanding about the development of web application by using
Java web programming language.

Muhammad Thariq bin Abdul Razak
Muhammad Fadli bin Setopa
Mohd Zuhair Shahiran bin Muhammad Najib

INTRODUCTION OF WEB DEVELOPMENT TECHNOLOGY
WORKBOOK ACTIVITY

III

ABSTRACT

This e-book was designed and developed for the DFP50173 - Web
Development Technology and DFP50283 - Web Development
Technology. This e-book contains laboratory activity related to the
web development technology by using a Java Programming language.
This e-book is a starting point for the Polytechnics students who just
started to learn and to understand the web application development
by using Java programming language. With this e-book, students will
explore the foundation of web application development by using Java
programming language and learn how Java can be manipulated to
achieve final expected results. The topics in this e-book consist of the
introduction to java web technology, developing a servlet,
introduction to java server pages (JSP), and deployment and security.
It is hoped that the production of this e-book will be a reference
materials for the students and lecturer who in enrolled for this
subject.

INTRODUCTION OF WEB DEVELOPMENT TECHNOLOGY
WORKBOOK ACTIVITY

IV

TABLE OF CONTENTS 1.0 INTRODUCTION TO JAVA WEB 01

TECHNOLOGY 02
1.1 Introduction of Web Application 11
27
2.0 DEVELOPING A SERVLET 38

2.1 Arrange Servlet File to Run in Browser
2.2 Construct the Servlet to Handle the
Client Request
2.3 Explain Data Validation in Dynamic
Web Pages
2.4 Produce Servlet File to Generate Server
Response: HTTP Response Headers

3.0 INTRODUCTION TO JAVA SERVER 46
65
PAGES (JSP) 77
3.1 Constructs the JSP File in Web
Application 82
3.2 Construct the Database with JDBC in 91
Web Application
3.3 Perform the Integration JSP and
Servlet in Project

4.0 DEPLOYMENT AND SECURITY
4.1 Produce Web Application Security in
Web Application

5.0 REFERENCES

INTRODUCTION OF WEB DEVELOPMENT TECHNOLOGY
WORKBOOK ACTIVITY

01

1. INTRODUCTION TO JAVA WEB
TECHNOLOGY

1.1 Explanation about Web Application

• A web application or web app is an program that is stored on a
remote server and sent over the internet through the browser
internet.

• All web-based database applications have three primary
components: A web browser (or client), a web application server,
and a database server (refer Figure 1.1).

• Web-based database applications rely on a database server, which
provides the data for the application. The database server
sometimes also provides business logic in the form of stored
procedures. Stored procedures can offer significant performance
advantages, especially in a multi-tiered architecture.

• The clients handle the presentation logic, which controls the way
in which users interact with the application. In some cases, the
client validates user-provided input. Web applications sometimes
integrate Java applets into the client-side logic to improve the
presentation layer.

Figure 1.1: web-based database applications

02

2. DEVELOPING A SERVLET IN JAVA

2.1 Arrange Servlet File to Run in Browser

Learning Outcomes

This lab activity encompasses FOUR(4) activities. (Activity 2.1A until 2.1D)
By the end of this lab, student should be able to:
I. Create a Servlet file
II. Mapping a servlet using

• Web.xml
• Annotation
III. Implement HTML Form

Activity 2.1A

Activity Outcome: Create new project using NetBeans.
Task 1 : Create New Project
a. Launch NetBeans software by clicking the icon on your desktop as shown in

Figure 2.1A(1).

Figure 2.1A(1): Launching NetBeans software
b. Select the New Project icon (or select File-> New Project) as shown in

Figure 2.1A(2)

Figure 2.1(2): create new project

03

2. DEVELOPING A SERVLET IN JAVA

Activity 2.1A

Activity Outcome: Create new project using NetBeans.
c. Select a Java Web project > Web Application then click the button Next > as

shown in Figure 2.1A(3)

Figure 2.1A(3): Select specific web project
d. Set the project the name as LabActivity2, then click Next > as shown in

Figure 2.1A(4)

Figure 2.1A(4): Create a suitable name for new project

04

2. DEVELOPING A SERVLET IN JAVA

Activity 2.1A

Activity Outcome: Create new project using NetBeans.
e. Select a suitable Server and Java EE version as shown in Figure 2.1A(5) and

click Finish.

Figure 2.1A(5): Server and settings configuration

05

2. DEVELOPING A SERVLET IN JAVA

Activity 2.1A

Activity Outcome: Create new project using NetBeans.
Task 2 : Create a servlet with web.xml file

a. Below the Web Pages entry, you will see a folder labeled Source
Packages. Right click on Source Packages, and select New and then
select Servlet as shown in Figure 2.1A(6).

Figure 2.1A(6): Create servlet file
b. Create a servlet with class name MyServlet and click Next. To create

the servlet with xml file, Mark (✓) on the Add information to
deployment descriptor (web.xml) and click Finish. Please refer Figure
2.1A(7) and Figure 2.1A(8)

Figure 2.1A(7): Servlet configuration

06

2. DEVELOPING A SERVLET IN JAVA

Activity 2.1A

Activity Outcome: Create new project using NetBeans.

Figure 2.1A(8): Configure servlet deployment
c. In the folder WEB-INF, the web.xml will be automatically created and

with the required elements tag as shown in Figure 2.1A(9).

Figure 2.1A(9): web.xml file

07

2. DEVELOPING A SERVLET IN JAVA

Activity 2.1A

Activity Outcome: Create new project using NetBeans.
d. Save, compile and run the project by click Run File in index.html as

shown in Figure 2.1A(10).

Figure 2.1A(10): index.html
e. The output should be as shown in Figure 2.1A(11).

Figure 2.1A(11): index.html output

08

2. DEVELOPING A SERVLET IN JAVA

Activity 2.1B

Activity Outcome: Create and mapping web.xml file.
a. In this task, user are required to download 2 html files (formSoccer.html

and formStudent.html) and 2 servlet java files (ProcessSoccer.java and
ProcessStudent.Java) from the URL below :

URL : https://tinyurl.com/WebDevelopmentTechnology
b. Then upload the html and servlets file to the current project which is

LabActivity2.1 project. The project LabActivity2.1 list of directory should
be as shown in Figure 2.1B(1).

Figure 2.1B(1): Upload required file
Task 1 : Mapping the other servlets in the web.xml
a. In the web.xml, to make mapping for others servlets in the project,

follow the following code as shown in Figure 2.1B(2). Complete the
servlets mapping for the ProcessSoccer servlets with the basic
element(s).

Figure 2.1B(2): web.xml source code

09

2. DEVELOPING A SERVLET IN JAVA

Activity 2.1B

Activity Outcome: Create and mapping web.xml file.
b. Save, compile and run the formSoccer.html and formStudent.html.

The output for formSoccer.html as shown in Figure 2.1B(3) and for
formStudent.html as shown in Figure 2.1B(4).
[Note: The web.xml file is the deployment descriptor for a Servlet-based
Java web application and it declares which Servlets exist and which URLs
they handle.]

Figure 2.1B(3): formSoccer.html output

Figure 2.1B(4): formStudent.html output

10

2. DEVELOPING A SERVLET IN JAVA

Activity 2.1C

Activity Outcome: Creating annotation in Servlets.
In this task, user are required to CONTINUE from the zip file given in Activity
2.1B. User will create annotation (@WebServlet) in servlets that can replace
equivalent XML configuration in the web deployment descriptor file
(web.xml) such as servlet declaration and servlet mapping.

Task 1 : Create an annotation
a. To create annotation inside the ProcessStudent.java servlet, modify the

existing source of code in ProcessStudent.java according to the Figure
2.1C(1).

Figure 2.1C(1): ProcessStudent.java source code

b. Save, compile and run the servlet. Observe the output.
c. Complete the task annotation in servlet with ProcesSoccer.java with

annotation.
[Note: The annotation (@WebServlet) in servlets that can replace
equivalent XML configuration in the web deployment descriptor file
(web.xml) such as servlet declaration and servlet mapping.]

11

2. DEVELOPING A SERVLET IN JAVA

2.2 CONSTRUCT THE SERVLET FILE TO HANDLE THE CLIENT
REQUEST

Learning Outcomes

This lab sheet encompasses SIX(6) activities. (Activity 2.2A until 2.2F)
By the end of this lab, student should be able to:

I. Understand HTTP GET and HTTP POST method
II. Writing servlet to get parameter values
III. Setting request attributes
IV. Use forward request

Activity 2.2A

Activity Outcome: Creating New Project AddNumber by implement HTTP POST
method.
Task 1 : Create New Project
a. Create a New Project AddNumber as a web project. Design and copy the

source code for index.html as shown in Figure 2.2A(1). Figure 2.2A(2)
shows the user interface of index.html.

Figure 2.2A(1): index.html source code

12

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2A

Activity Outcome: Creating Project AddNumber by implement HTTP POST
method.

Figure 2.2A(2): index.html user interface
b. Next, create a new Servlet file which is calculate.java and copy the source

code at doPost function as shown in Figure 2.2A(3). Save, compile and run
the file index.html. The output of index.html as shown in Figure 2.2A(4) -
Figure 2.2A(5).

Figure 2.2A(3): calculate.java source code

Figure 2.2A(4): index.html output

Figure 2.2A(5): index.html output

13

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2B

Activity Outcome: Implement HTTP GET method
Task 1 : Use the existing AddNumber project and implement HTTP GET method.
a. By using the existing project in Activity 2.2A, create a new html file which is

ViewNumber.html as a web project. Copy the source code for
ViewNumber.html as shown in Figure 2.2B(1). Figure 2.2B(2) shows the user
interface for ViewNumber.html.

Figure 2.2B(1): ViewNumber.html source code

Figure 2.2B(2): ViewNumber.html user interface

14

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2B

Activity Outcome: Implement HTTP GET method
b. Create a new servlet file which is Add_process.java and update the source

code by using doGet function as shown in Figure 2.2B(3). Save, compile and
run the file ViewNumber.html. This project is used to calculate the sum of
two numbers. The output of the calculation of two numbers is as shown in
Figure 2.2B(4) – Figure 2.2B(5).

Figure 2.2B(3): Add_process.java source code

Figure 2.2B(4): ViewNumber.html output

Figure 2.2B(5): ViewNumber.html output

15

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2C

Activity Outcome: Writing servlet file to get parameter values
Task 1 : Create New Project to get parameter values
a. Create a library_registration as a new web project. Then create new

register.html and copy the source code as shown in Figure 2.2C(1) that
implement POST method.

Figure 2.2C(1): register.html source code
b. Save, compile and run register.html and the output should be as shown in

Figure 2.2B(2)

Figure 2.2B(2): register.html interface

16

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2C

Activity Outcome: Writing servlet file to get parameter values
c. Next, create new servlet file namely library.java and copy the source code as

shown in Figure 2.2C(3) by implementing getParameter() method.

Figure 2.2C(3): library.java source code
d. Save, compile and run register.html file. The output should be as shown in

Figure 2.2C(4) and Figure 2.2C(5).

Figure 2.2C(4): register.html user insert data

Figure 2.2C(5): register.html output

17

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2C

Activity Outcome: Writing servlet file to get parameter values
e. Next, modify the register.html source code by implementing the multiple

checkbox to allow user to tick more than one option for book genre as
shown in Figure 2.2C(5).

Figure 2.2C(5): register.html modified source code
f. Save, compile and run the register.html and the output should be as shown

in Figure 2.2C(6).

Figure 2.2C(6): register.html output

18

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2C

Activity Outcome: Writing servlet file to get parameter values
g. Then, modify the existing source code in library.java code to implement

getParameterValue() method to read genre from register.html page as
shown Figure 2.2C(7).

Figure 2.2C(7): library.java modified source code
h. Save, compile and run the register.html. The output should be as shown in

Figure 2.2C(8) and Figure 2.2C(9).

Figure 2.2C(8): register.html output

Figure 2.2C(9): register.html output

19

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2D

Activity Outcome: Setting request attributes
Task 1 : Create New Project to setting request attributes
a. Create a LoginSession as a new web project. Then, create new login.html

and copy the source code that implement POST method as shown in
Figure 2.2D(1).

Figure 2.2D(1): login.html source code
b. Save, compile, run the login.html and the output should be as shown in

Figure 2.2D(2).

Figure 2.2D(2): register.html interface

20

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2D

Activity Outcome: Setting request attributes
c. Create a html file with the name of ReadSessionInfo.html and write the

source code as shown in Figure 2.2D(3).

Figure 2.2D(3): ReadSessionInfo.html source code
d. Save, compile and run the ReadSessionInfo.html and the output should be

as shown in Figure 2.2D(4).

Figure 2.2D(4): ReadSessionInfo.html output

21

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2D

Activity Outcome: Setting request attributes
e. In the source packages, create a new package with the name of

Login_Package (Please refer to Figure 2.2D(5)). In the Login_Package, create
two Servlet file which are Session_Demo.java and Session_Info.java.
Complete both servlets source code as shown in Figure 2.2D(6) and Figure
2.2D(7).

Figure 2.2D(5): Structure of Login_Package

22

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2D

Activity Outcome: Setting request attributes

Figure 2.2D(6): Session_Demo.java source code

Figure 2.2D(7): Session_Info.java source code

23

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2D

Activity Outcome: Setting request attributes
f. Please write the source code to import specific package as shown in Figure

2.2D(8).

Figure 2.2D(8): Import related package
g. After that, save, compile and run the LoginPage.html file. Test your Login

with the correct username and password (username: administrator,
password : administrator). The output should be as shown in Figure 2.2D(9).

Figure 2.2D(9): LoginPage.html output

24

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2D

Activity Outcome: Setting request attributes
h. If the login status is success then you can read the session information by

clicking link “Login Success !” . Example as shown in Figure 2.2D(10).

Figure 2.2D(9): LoginPage.html output
i. After click the link in Figure 2.2D(9), then it will redirected to the

ReadSessionInfo.html to read the session data as shown in Figure
2.2D(10).

Figure 2.2D(10): ReadSessionInfo.html output
j. Then, when button “Read session data” is clicked, all session information

about the specific log in user is displayed as shown in Figure 2.2D(11)

Figure 2.2D(11): ReadSessionInfo.html output

25

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2E

Activity Outcome: Setting forward request
Task 1 : Create New Project for setting forward request
a. Using the same project from Activity 2.2D, create new

login_fwrd_request.html (using POST method) and servlet file namely
login_fwrd_request.java and copy the source code as shown in Figure
2.2E(1) and Figure 2.2E(2).

Figure 2.2E(1): login_fwrd_request.html source code

Figure 2.2E(2): login_fwrd_request.java servlet source code

26

2. DEVELOPING A SERVLET IN JAVA

Activity 2.2E

Activity Outcome: Setting forward request
b. Create a servlet file namely WelcomeServlet.java and copy the source code

based on Figure 2.2E(3).

Figure 2.2E(3): WelcomeServlet.java servlet source code
c. Save, compile and run the login_fwrd_request.html. The output as shown in

Figure 2.2E(4).

Figure 2.2E(4): login_fwrd_request.html output

27

2. DEVELOPING A SERVLET IN JAVA

2.3 EXPLAIN DATA VALIDATION IN DYNAMIC WEB PAGES

Learning Outcomes

This lab sheet encompasses TWO(2) activities. (Activity 2.3A until 2.3B)
By the end of this lab, student should be able to:

I. Validating data on the client side
II. Validating data on server side

Activity 2.3A

Activity Outcome: Validating data on the client-side.
Task 1 : Create New Project for validation on the client side
a. Create a New Project namely LabActivity2.3 as a web project. Then

modify the index.html source code as shown in Figure 2.3A(1).

Figure 2.3A(1): index.html source code

28

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3A

Activity Outcome: Validating data on the client-side
b. Save, compile and run index.html and the output should be as shown in

Figure 2.3A(2)

Figure 2.3A(2): index.html interface
c. Create a new html file namely formValidation1.html and update the source

code as shown in Figure 2.3A(3) - Figure 2.3A(4). This form will be using the
client validation data by using <script> mechanism function with verify()
method.

Figure 2.3A(3): formValidation1.html source code

29

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3A

Activity Outcome: Validating data on the client-side

Figure 2.3A(4): formValidation1.html source code

30

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3A

Activity Outcome: Validating data on the client-side
d. Save, compile and run file formValidation1.html and the output should be as

shown in Figure 2.3A(5).

Figure 2.3A(5): formValidation1.html output
e. Verify() method is a function called/triggered when the button Submit is

clicked. Verify() method will validates the name, IC number and whether the
radio button gender is selected or not. If user input is not match with the
Verify() method validation requirement, proper alert message is displayed to
notified user. Example of error message as shown in Figure 2.3A(6).

Figure 2.3A(6): Proper alert message displayed if validation process failed

31

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3A

Activity Outcome: Validating data on the client-side
e. In the existing project source packages, create a new Java Package with the

name of LabAct3. In this package, create a new Servlet ValidationClient.java.
Copy and modify the ValidationClient.java source code in the
processRequest() method as shown in Figure 2.3A(7) – Figure 2.3A(8).

Figure 2.3A(7): ValidationClient.java source code

32

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3A

Activity Outcome: Validating data on the client-side

Figure 2.3A(8): ValidationClient.java source code

33

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3A

Activity Outcome: Validating data on the client-side
g. Save, compile and run formValidation1.html. Test your form data validation

as in Figure 2.3A(6) and if all the required data is entered correctly and
submitted, you will get a successful data submission notification as shown in
Figure 2.3A (9).

Figure 2.3A(9): Successful data submission notification

34

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3B

Activity Outcome: Validating data on the server-side.
Task 1 : Implement validation method on the server side
a. Using a existing LabActivity2.3 project, create a web page namely

formValidation2.html and write the source code as shown in Figure
2.3B(1). formValidation2.html will implement data validation in the
server-side.

Figure 2.3B(1): FormValidation2.html source code

35

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3B

Activity Outcome: Validating data on the server-side.
b. Save, compile and run formValidation2.html and the output should be as

shown in Figure 2.3B(2)

Figure 2.3B(2): FormValidation2.html interface
c. In source package LabActivity2.3, create a new Servlet ValidationServer.java

and in the processRequest method, complete the servlet source code as
shown in Figure 2.2B(3) - Figure 2.2B(4).

Figure 2.3B(3): ValidationServer.java source code

36

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3B

Activity Outcome: Validating data on the server-side.

Figure 2.3B(4): ValidationServer.java source code

37

2. DEVELOPING A SERVLET IN JAVA

Activity 2.3B

Activity Outcome: Validating data on the server-side.
d. Save, compile and run the project to execute the formValidation3.html. If

user insert a wrong input then a proper error message is displayed. Example
of the execution of the data validation in server side shown in Figure 2.2B(5)

Figure 2.3B(5): Example of data validation on server side
e. If the server validation failed, proper alert message is displayed to notify the

user as shown in Figure 2.3B(6)

Figure 2.3B(6): Example of data validation on server side

38

2. DEVELOPING A SERVLET IN JAVA

2.4 PRODUCE SERVLET FILE TO GENERATE SERVER RESPONSE:
HTTP RESPONSE HEADER

Learning Outcomes

This lab sheet encompasses THREE (3) activities. (Activity 2.4A until 2.4C)
By the end of this lab, student should be able to:

I. Understand the format of the HTTP response
II. Setting response header
III. Use redirect Response

Activity 2.4A

Activity Outcome: Understand the format of the HTTP response.
Task 1 : Create New Project for validation on the client side
a. Create a New Project namely LabActivity2.4. Then, create a pizza.html

and follow the source code as shown in Figure 2.4A(1). Figure 2.4A(2)
shows the user interface of pizza.html.

Figure 2.4A(1): pizza.html source code

39

2. DEVELOPING A SERVLET IN JAVA

Activity 2.4A

Activity Outcome: Understand the format of the HTTP response.

Figure 2.4A(2): pizza.html interface
b. In source packages, create a new servlet file namely

DisplayHeadersServlet.java and follow the source code as shown in Figure
2.4A(3).

Figure 2.4A(3): DisplayHeadersServlet.java source code

40

2. DEVELOPING A SERVLET IN JAVA

Activity 2.4A

Activity Outcome: Understand the format of the HTTP response.
c. Save, compile, run pizza.html and fill up all the input required as shown in

Figure 2.4A(4).

Figure 2.4A(4): pizza.html interface
d. Before click Order Pizza button, please open network tab at the Inspect

element as shown in Figure 2.4A(5) - Figure 2.4A(6).

41

2. DEVELOPING A SERVLET IN JAVA

Activity 2.4A

Activity Outcome: Understand the format of the HTTP response.

Figure 2.4A(5): Inspect Element

Figure 2.4A(6): HTTP response output

42

2. DEVELOPING A SERVLET IN JAVA

Activity 2.4A

Activity Outcome: Understand the format of the HTTP response.
d. Then, click “Order Pizza” button and observe the output. The output should

be as shown in Figure 2.4A (7).

Figure 2.4A(7): HTTP request and HTTP response

43

2. DEVELOPING A SERVLET IN JAVA

Activity 2.4B

Activity Outcome: Setting response header.
Task 1 : Setting the Response Header
a. Use the same project at Activity 2.4A, modify the existing

DisplayHeaderServlet.java source code by adding the setHeader method.

Figure 2.4B(1): Modified DisplayHeaderServlet.java Source Code
b. Save, compile and run the pizza.html. Observe the output at the network

tab. The output should be as shown in Figure 2.4B(2).

Figure 2.4B(2): HTTP request and HTTP response output

44

2. DEVELOPING A SERVLET IN JAVA

Activity 2.4C

Activity Outcome: Use Redirect Response.
Task 1 : Implement Redirect Response
a. Use the same project at Activity 2.4B, create new file namely redirect.html

and follows the source code as shown in Figure 2.4C(1). Figure 2.4C(2) show
the user interface of redirect.html.

Figure 2.4C(1): redirect.html source code

Figure 2.4C(2): redirect.html user interface
b. Then, create new servlet file with the name of redirect.java and follow the

source code by using POST method as shown in Figure 2.4C(3).


Click to View FlipBook Version