Table of Contents
1.
Introduction
2.
3.
4.
Concept Map
4.1 Servlet Life Cycle:
4.2 Starting Servlets
4.2.1 HTTP Methods
4.3 Servicing a Servlet
3
3
4
4
5
5.
6.
5
5
6
7
7
7
7
7
7
7
8
8
9
7.
Practice Tasks
7.1 Practice Task 1
11
11
8.
12
9.
Evaluation Criteria
13
10.
Further Reading
13
Page | 2
Activity time
Total Time
10 min
10 min
10 min
10 min
70 min
70 min
As per time specified for 40 min
each task
25 min for each assigned 50 min
task
4. Concept Map
4.1 Servlet Life Cycle:
The life cycle of a servlet is controlled by the container in which the servlet has been deployed.
Page | 3
POST:
Data sent in two steps
Designed for Posting information
Browser contacts server
Sends data
GET:
Contacts server and sends data in single step
Appends data to action URL separated by question mark
Designed to get information
Page | 4
Page | 5
2
3
4
PASSWORD
------------------------- -----------------------abc
xyz
This section is designed such a way that you can complete the following tasks independently.
However if there is any ambiguity you can refer it to the lab instructor.
6.4.1
1.
2.
3.
4.
5.
HelloServlet
Right click on Source Packages>New>Servlet.
Type servlet name HelloServlet.
Type Package name com.servlets.HelloServlet. Click next
Check Add information to Deployment Descriptor (web.xml).
Click Finish.
Page | 7
3. Within servlet tag we can add initialization parameter information. Lets add two
Parameters University and Website. Shown as below:
4. Each Parameter has two tags: its name and its value. Throughout the application we can
access the parameter value by calling its name.
5. Save the changes (Ctrl+s) and close web.xml
6.4.3 Accessing initialization parameters in Servlet
1. Open HelloServlet.
Page | 8
4. Run ColorExample.
Page | 10
7. Practice Tasks
This section will provide more practice exercises which you need to finish during the lab. You
need to finish these tasks in the required time. Once you have completed your tasks kindly place
them in the folder provided by your lab instructor.
7.1 Practice Task 1
[Expected Time: 50 min]
Create a servlet that establishes a connection using init parameters to define the details of the
connection.
1. Pass the Retrieved information to establishConnection().
Page | 11
Page | 12
9. Evaluation Criteria
The evaluation criteria for this lab will be based on the completion of the following tasks. Each
task is assigned the marks percentage which will be evaluated by the instructor in the lab whether
the student has finished the complete/partial task(s).
Table 2: Evaluation of the Lab
Sr. No
1
2
Task No.
5
6.2
6.3
3
4
6.4
8
Task Description
Homework
Setting up to use
MySQL
Setting up to use
NetBeans IDE
Walk Through Tasks
Evaluation
Tasks
(unseen)
Total
Grade
5
10
10
30
45
100
Page | 13