Monday 19 February 2018

1.0 JSP & Servlets

BASIC CONCEPTS OF CLIENT AND SERVER

Web Server - A web server takes client request and give something back as a result.















Client and server know HTML and HTTP
HTML - Tells the browser how to display
HTTP -  Hypertext Transfer Protocol , client and server use it to communicate.

HTTP runs on top of TCP and IP protocol
TCP - Transmission/Transfer control protocol is responsible for making sure that the the transmitted file from source reach at destination as a complete singe file
IP - Internet Protocol decides the best route to deliver the packet at the destination.


















HTTP response contains header having all the information regarding the response.
In HTTP request - GET and POST



























GET VS POST














PORTS - A single server supports many ports. A server application identified by a port.

FTP - 21
TELNET - 23
SMTP - 25
TIME - 37
HTTP - 80
POP3 - 110
HTTPS - 443

0 - 1023 are reserved ports. A server can have 65536 ports.

But sometimes you just need more than a web server.Web server simply fetch the static page request and give it back to client. On web server machine there are many applications which can provide the desired dynamic output where computation involves.


What is a CONTAINER -  TOMCAT is an example of container
When a web server application like apache gets a request for servlet, then its not the apache who hands over the HTTP request to the servlet , It is a CONTAINER (TOMCAT) that calls doPost() and doGet() methods of a servlet.


  1. Container provides communication support between web server and your servlet. You don't have to build a server socket etc.
  2. Container controls the lifecycle of your servlet
  3. Multithreading support for every request
  4. Translation of JSP to java.

How does container handles a request

  1. User clicked a link - which is a request for a servlets
  2. The containers sees that the request is for servlet so it create two objects (HttpServletRequest and HttpServletResponse)
  3. Container finds the correct servlet based on the request and allocate a thread for the request, and passes the request and response object to the servlet thread
  4. The container calls the service() method of servlet. Depending upon the request service methods calls either doGet() or doPost().
  5. The doGet() or doPost() method will generate the response and pass it to the HttpResponse Object.
  6. The Container create the HttpResponse Object into HTTP response and send it back to the client.
SERVLET LIFE CYCLE




MVC






















VIEW - Responsible for the presentation
CONTROLLER - Takes user inputs and figure out what it means to the model.
MODEL - Holds the real business logic.



No comments:

Post a Comment