Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Lecture Assignment

Tutorial Week 4
Our readings (lecture notes and video lecture) this week discuss the fundamental of web
technology and introduction to Servlet. Write the answers for all questions in the table according
to your understanding. PLEASE USE YOUR OWN WORDS. DO NOT COPY FROM THE
WEB.

Questions Answers
1. Explain how servlets works based on below figure. The HTTP Client sends a
request message to a HTTP
Server through the HTTP
over TCP/IP.

Then, the HTTP Server starts


a servlet and computes a
result for the HTTP Client
request

After all processing, the


HTTP Server will return the
message back to the HTTP
Client over the TCP/IP
network
2. Differentiate between HTTP Get and HTTP Post. HTTP Get
- Usually gets a content
of a specified URL
- Not secured
- Can be book marked
HTTP Post
- Used to post data to
server-side form
handler
- It is secured
- Cannot be
bookmarked
3. Can you display an HTML file by typing the complete file No, you must copy the file
name in the url such as http://test.html? from the directory first.

MMR2020@FSKM
Lecture Assignment

Can you run a servlet by simply typing the servlet class file No,
name?
4. Let say you develop a servlet by defining a class name No, you need to use the
ListLibraryServlet that extends HttpServlet class. servlet.
No, it will show error

In the Servlet, you have doGet and doPost methods.


Explain the purpose of these methods. Lecture Assignment

MMR2020@FSKM

4. Let say you develop a


servlet by defining a class
name
ListLibraryServlet that
extends HttpServlet class.

In the Servlet, you have


doGet and doPost methods.
Explain the purpose of these
methods.

Method doGet
- Responds to GET requests
- Default action:
BAD_REQUEST error (file
not found)
- Override for custom GET
processing
- Arguments represent client
request and server response
5. Describe the life cycle of a servlet. - Servlet class is
loaded
- Servlet instances is
created

MMR2020@FSKM
Lecture Assignment

- Init method is invoked


- Service methos is
invoke
- Destroy methos is
invoke
6. Suppose you write and run the following servlet twice by First call: constructor called.
issuing appropriate URL from a web browser, and finally stop Then init called, next do get
the GlassfishServer. What was displayed on the console called
when the servlet was first called/invoked? What was
displayed on the console when the servlet was invoked for Second call: doGet called
the second time? What was displayed on the console when
glassfish server was shut down? Server shutdown: Destroy
called

7. Explain the difference between HTTP request and HTTP - HTTP Request
response. defines a more
general interface to
provide information

Lecture Assignment

MMR2020@FSKM
for all kinds of clients.
- HTTP Response
defines a more
general interface for
sending output to the

MMR2020@FSKM
Lecture Assignment

client.
8. Find an example of code that use HTTP request for Servlet. public class HTTPGetServlet
Explain. extends HttpServlet {

public void doGet(


HttpServletRequest request,
HttpServletResponse
response )
throws ServletException,
IOException
9. Find an example of code that use HTTP response for public class HTTPPostServlet
Servlet. Explain. extends HttpServlet {}

public void doPost(


HttpServletRequest request,
14
HttpServletResponse
response )
15 throws ServletException,
IOException

MMR2020@FSKM

You might also like