Escolar Documentos
Profissional Documentos
Cultura Documentos
Web Server
A web server takes a client request and gives
something back to the client.
A web browser gets user request resource, find
the resource and returns something to the user.
Sometimes that resource is an HTML page.
Sometimes its a picture. Or Sometimes a sound
file. Or even a PDF document.
If the requested resource not available 404 Not
Found error-the response you get when the
server cant find what it thinks you asked for.
A server means either the physical
machine(hardware) or the web server
application(software).
Web client
A web client lets the user request
something on the server, and shows the
user the result of the request.
When we talk about client, though, we
usually mean both the human user and
the browser application.
The browser is the piece of software (like
Mozilla, Netscape ..)that knows how to
communicate with the server.
The browsers other big job is interpreting
the HTML code and rendering the web
page for the user.
HTTP:
Most of the conversations held on the web
between clients and servers are held using
the HTTP protocol, which allows for simple
request and response conversations.
The clients sends an HTTP request, and the
server answers with an HTTP response.
If you are a web server ; you speak
HTTP.
When a web server sends an HTML page to
the client, it sends it using HTTP(Hyper Text
Transfer Protocol).
HTML Basics
HTTP Request
Key elements of a request
stream:
HTTP Response
Key elements of a response
stream:
Form parameters.
The content ( the actual
content).
HTTP
Request
Server
<html>
<head>
<html>
<body>
<head>
<body>
Client
response
HTTP
HTML
HTTP Response
HTTP Request
The first thing youll find is an HTTP
method name.
The method name tells the server the
kind of request thats being made, and
how the rest of the message being
formatted.
The HTTP protocol has several methods,
but the ones youll use most often are
GET and POST.
Get or Post ?
What is a Container?
Servlets dont have a main() method. Theyre under the control
of another Java application called a Container.
Tomcat is an example of a Container.
When your web server application (like Apache) gets a request
for a servlet, the server hands the request not to the servlet
itself, but to the Container in which the servlet is deployed.
Its the Container that gives the servlet the HTTP request and
response, and its the Container that calls the servlets
methods (like doPost() or doGet()).
Web container(also known as a Servlet container) is the
component of aweb serverthat interacts withJavaservlets.
A web container is responsible for managing the lifecycle of
servlets, mapping aURLto a particular servlet and ensuring
that the URL requester has the correct access rights.
Lifecycle Management :
The Container controls the life and death of your servlets. It takes
care of loading the classes, instantiating and initializing the servlets,
invoking the servlet methods, and making servlet instances eligible
for garbage collection.
With the Container in control, you dont have to worry as much about
resource management.
Multithreading Support :
The Container automatically creates a new Java
thread for every servlet request it receives.
When the servlets done running the HTTP service
method for that clients request, the thread completes
Declarative Security :
With a Container, you get to use an XML deployment
descriptor to configure (and modify) security without
having to hard-code it into your servlet (or any other)
class code.
Think about that! You can manage and change your
security without touching and recompiling your Java
source files
JSP Support :
JSPs are nothing but Java inside HTML.
The container translates the JSP into Java for you.
Deployment Descriptor
The deployment descriptor (DD), provides a declarative
mechanism for customizing your web applications without
touching source code!
Besides mapping URLs to actual servlets, you can use the
DD to customize other aspects of your web application
including security roles, error pages, tag libraries, initial
configuration information.
DD Benefits
Minimizes touching source code that has already been tested.
Lets you fine-tune your apps capabilities, even if you dont have
the source code.
Lets you adapt your application to different resources (like
databases), without having to recompile and test any code.
Makes it easier for you to maintain dynamic security info like
access control lists and security roles.
Lets non-programmers modify and deploy your web applications
while you can focus on the more interesting things.