Best Webservice Training Institute in Chennai

Introduction to Web

Web consists of billions of clients and server connected through wires and wireless networks. The web clients make requests to web server. The web server receives the request, finds the resources and return the response to the client. When a server answers a request, Best Java WebService Training In Chennai it usually sends some type of content to the client. The client uses web browser to send request to the server. The server often sends response to the browser with a set of instructions written in HTML(HyperText Markup Language). All browsers know how to display HTML page to the client.


Web Application

A website is a collection of static files(webpages) such as HTML pages, images, graphics etc. A Web application is a web site with dynamic functionality on the server. Google, Facebook, Twitter are examples of web applications.


HTTP (Hypertext Transfer Protocol)

  • HTTP is a protocol that clients and servers use on the web to communicate.
  • It is similar to other internet protocols such as SMTP(Simple Mail Transfer Protocol) and FTP(File Transfer Protocol) but there is one fundamental difference.
  • HTTP is a stateless protocol i.e HTTP supports only one request per connection. This means that with HTTP the clients connect to the server to send one request and then disconnects. This mechanism allows more users to connect to a given server over a period of time.
  • The client sends an HTTP request and the server answers with an HTML page to the client, using HTTP.

HTTP Methods

HTTP request can be made using a variety of methods, but the ones you will use most often are Get andPost. The method name tells the server the kind of request that is being made, and how the rest of the message will be formated.

HTTP Methods and Descriptions :

Method NameDescription

OPTIONS

Request for communication options that are available on the request/response chain.

GET

Request to retrieve information from server using a given URI.

HEAD

Identical to GET except that it does not return a message-body, only the headers and status line.

POST

Request for server to accept the entity enclosed in the body of HTTP method.

DELETE

Request for the Server to delete the resource.

CONNECT

Reserved for use with a proxy that can switch to being a tunnel.

PUT

This is same as POST, but POST is used to create, PUT can be used to create as well as update. It replaces all current representations of the target resource with the uploaded content.


Difference between GET and POST requests

GET RequestPOST Request

Data is sent in header to the server

Data is sent in the request body

Get request can send only limited amount of data

Large amount of data can be sent.

Get request is not secured because data is exposed in URL

Post request is secured because data is not exposed in URL.

Get request can be bookmarked and is more efficient.

Post request cannot be bookmarked.


General Difference between PUT and POST methods

Following are some basic differences between the PUT and the POST methods :

  • POST to a URL creates a child resource at a server defined URL while PUT to a URL creates/replaces the resource in its entirety at the client defined URL.
  • POST creates a child resource, so POST to /books will create a resources that will live under the/books resource. Eg. /books/1. Sending the same post request twice will create two resources.
  • PUT is for creating or replacing a resource at a URL known by the client.
  • PUT must be used for CREATE when the client already knows the url before the resource is created.
  • PUT replaces the resource at the known url if it already exists, so sending the same request twice has no effect. In other words, calls to PUT are idempotent.

Anatomy of an HTTP GET request

Get request contains path to server and the parameters added to it.


Anatomy of an HTTP POST request

Post requests are used to make more complex requests on the server. For instance, if a user has filled a form with multiple fields and the application wants to save all the form data to the database. Then the form data will be sent to the server in POST request body, which is also known as Message body.

Introduction to Servlet

Servlet Technology is used to create web applications. Servlet technology uses Java language to create web applications.

Web applications are helper applications that resides at web server and build dynamic web pages. A dynamic page could be anything like a page that randomly chooses picture to display or even a page that displays the current time.

As Servlet Technology uses Java, web applications made using Servlet are Secured, Scalable and Robust.


CGI (Common Gateway Interface)

Before Servlets, CGI(Common Gateway Interface) programming was used to create web applications. Here’s how a CGI program works :

  • User clicks a link that has URL to a dynamic page instead of a static page.
  • The URL decides which CGI program to execute.
  • Web Servers run the CGI program in seperate OS shell. The shell includes OS enviroment and the process to execute code of the CGI program.
  • The CGI response is sent back to the Web Server, which wraps the response in an HTTP response and send it back to the web browser.

Drawbacks of CGI programs

  • High resposne time because CGI programs execute in their own OS shell.
  • CGI is not scalable.
  • CGI programs are not always secure or object-oriented.
  • It is Platform dependent.

Because of these disadvantages, developers started looking for better CGI solutions. And then Sun Microsystems developed Servlet as a solution over traditional CGI technology.


Advantages of using Servlets

  • Less response time because each request runs in a separate thread.
  • Servlets are scalable.
  • Servlets are robust and object oriented.
  • Servlets are platform independent.

Servlet Life Cycle

  1. Loading Servlet Class : A Servlet class is loaded when first request for the servlet is received by the Web Container.
  2. Servlet instance creation :After the Servlet class is loaded, Web Container creates the instance of it. Servlet instance is created only once in the life cycle.
  3. Call to the init() method : init() method is called by the Web Container on servlet instance to initialize the servlet.

Signature of init() method :

  1. Call to the service() method : The containers call the service() method each time the request for servlet is received. The service() method will then call the doGet() or doPost() methos based ont eh type of the HTTP request, as explained in previous lessons.

Signature of service() method :

  1. Call to destroy() method: The Web Container call the destroy() method before removing servlet instance, giving it a chance for cleanup activity.
Show your support

Clapping shows how much you appreciated dinju’s story.