Professional Documents
Culture Documents
Class3 Servlets 1
Class3 Servlets 1
Class3 Servlets 1
Todays Objectives
HTTP methods Servlet API Dynamic Environment Setup
Revisiting HTTP
Concepts
Connection Oriented Stateless Protocol
Persistent connection Uses TCP/IP sockets (well known port 80)
Revisiting HTTP
Safe Methods
Only request information
Do not change state on the server May return different responses
Idempotent Methods
Making a request multiple times has same effect Client can retry method on network/softare failure
Revisiting HTTP
Safe : No.
Safe : No.
Idempotent: Yes.
Idempotent: Yes.
DELETE
Spying on HTTP
liveHttpHeaders for Firefox
Fiddler for IE
Servlet
contraction of a server-let
Managed component deployed to a container provided with lifecycle and enterprise services Focus on high level abstractions
Requests Responses Sessions
Container Responsibilities
Knows HTTP Creates the request and response objects Determines the request handler servlet Loads/initializes the servlet, if first time Allocate a request processing thread Calls the servlets service() method Converts response object to HTTP response Deletes the request and response objects Destroys the servlet
Servlets Overview
States
Does not exist Initialized
init()
contains initialization code called after instance created, but before service()
service()
called once per request called on its own request thread invokes doXXX() based on HTTP method
destroy()
Servlet Names
Servlet Names
Advantages
Flexibility: classes can move without client changes Security: hides implementation details
Configuring a Servlet
Request
Response
Interface Protocol spesific Content specific text/html, image/jpeg,
Interface
Development vs Deployment