Skip to main content

Introduction to Java Servlets

In order to understand the advantages of servlets , you must have the basic under standing of how web browser and web servers are cooperate to provide content to the client . For sake of argument , consider a request for a static web page. The user enters a Uniform Resource Locator( URL) . Then the browser generate a HTTP request for the appropriate server ; the server redirect to the request to the index file of the specified web site . That file return a HTTP response to the client .HTTP header in the HTTP response indicates that the content type of the response. Multipurpose Internet Mail Extension(MIME) is used to the same purpose. for example HTML(Hypertext Markup language ) have a mime type of text/html

       In the early days of web, the web server construct a dynamic web page by creating separate process to handle simultaneous request from the client .the process need to open one or more connection to the database to obtain the necessary information. It is communicate with the server using a interface called Common Gateway Interface (CGI). CGI allow process to read data from http request and write data to the http response as well.CGI program can written in a variety of language like c cpp perl and so on.
   

    A Java Servlet is server side program that called by user interface or by another web component and contain business logic to process a request. Java servlet are runt in the address space of the web server and act as a middle layer between request coming from the client or browser  and database or application resides in the server . Usually the business logics are written in servlet ie code related to database manipulation and as we know all other presentation code will be written in jsp .Using servlet you can collect data from user through web forms . display data from database and from other source as well and create web page dynamically .

   Servlets serve the same purpose as same as the program implementing CGI. But servlet offer some advantages over CGI.

-> It is significantly better performance
-> Platform independent since it is written in java
->  Servlets are run with in the address space of the server. There is no need to create separate process to handle simultaneous request from the client.   Mulithreading helps to servlet to do the same .
->Security manager in the server enforce some restrictions to protect the resource in the server machine. So we can trust servlet blindly .
->Full functionality of the java class library are available to the servlet . ie it can communicate with database , applet and other software through RMI,sockets and so forth .

Servlets are responsible to do the following tasks .

->  Read the explicit data from client(browser) . it may include data from web forms , applet or from http custom client .

-> Read the implicit HTTP Request data from client(browser). It may include content type ,cookies , compression schema which understand by the browser and so forth .

-> Process the data and generate the result or HTTP response . This process may need to talk with database may invoke RMI, CORBA ,or compute the request directly

->Send explicit data to the client(Browser). This data can be send to the client in a variety of forms like text(html,xml), excel ,binary (GIf image ).

-> Send implicit data to the client(Browser). This may include tell browser or client side application what type of data being send,Cookies , Caching parameters and things like that



Comments