Introduction to Web Application Technologies : Part-II

In the previous part of Web Application Technologies we had discussed about HTTP Client Server Architecture and Uniform Resource Locator. Today we will discuss about another few interesting technologies.

Web Sites and Web Applications:

  • A web site is a collection of the static files, HTML pages, graphics, and various other files. A web application is the web site with a dynamic functionality on the server.A web application doesrun programs on the server , for example:
  • A browser does make a request, to the server, for an HTML form.
  • The server does respond by sending the HTML form back to the browser in an HTTP request stream.
  • Next, the browser does send another request, with the data form the HTML form, to the server.
  • The server does passe the request and data to a program that responds by sending data back to the browser.

Note: Do not confuse web application with web services. Web services are services that are offered by one application to another over the World Wide Web. They typically involve the transfer of data in Extensible Markup Language (XML) format using SOAP in business-to-business (B-to-B) transactions.

Execution of CGI Programs:

  • Early in the development of HTML, the designers created a mechanism to permit a user to invoke a program on the web server. This mechanism was called the Common Gateway Interface (CGI). When a web site includes CGI processing, this is called a web application.
  • Usually, the browser needs to send data to the CGI program on the server. The CGI specification defines how the data is packaged and sent in the HTTP request to the server. This data is usually typed into the web browser in an HTML form.
  • The URL determines which CGI program to execute. This might be a script or an executable file. The CGI program parses the CGI data in the request, processes the data, and generates a response (usually an HTML page).
  • The CGI response is sent to web server, which does wrap the response in the HTTP response,then the HTTP response is sent back to the web browser.
  • The figure given below shows an example web application architecture that uses CGI programs.
  • At runtime, the CGI program is launched by the web server as a separate OS shell. The shell does include an OS environment and process to execute the code of the CGI program, which resides within the server’s file system.
  • The figure given below shows the runtime performance of one CGI request.
  • However, each new CGI request launches a new operating system shell on the server.
  • The figure given below shows the runtime performance of multiple requests.

 

Introduction to Web Application Technologies_2

 

Advantages and Disadvantages of CGI Programs:

CGI programs have the following advantages:

  • Programs can be written in variety of languages, although they are primarily written in Perl.
  • The CGI program with bugs does not crash the web server.
  • Programs are easy for a web designer to reference. When the script written, the designer can reference it in one line in a web page.
  • Because the CGI programs do execute in their own OS shell, these program do not have concurrency conflicts with other HTTP requests executing the same CGI program.
  • All services provides supports CGI programs.

CGI programs also have the following distinct disadvantages:

  • The response time of the CGI programs is high because CGI program execute in their own OS shell. The creation of an OS shell is a heavyweight activity for the OS.
  • CGI is not scalable. If the number of people accessing the web application increases from 50 to 500, for example, CGI cannot be adapted to handle the load. There is limit on the number of separate OS processes a computer can run.
  • The languages for the CGI are not always secure or object oriented.
  • The CGI script has to generate an HTML response, so the CGI code is mingled with HTML. This is not good separation of presentation and business logic.
  • Scripting languages are often platform independent.

Because of these disadvantages, developers need other CGI solutions. Servlet is the Java technology solution is used to process CGI data.

Execution of Java Servlet:

  • Sun microsystems developed servlets as an advance over traditional CGI technology. A Java servlet is a Java technology program that, similar to a CGI program, runs on the server.
  • The types of tasks that you can run with servlets are similar to those you can run with CGI. However, the underlying executing architecture is different.
  • As with CGI scripts, you can write servlets that recognize HTTP requests, generates the response dynamically (possibly querying databases to fulfill the request), and then send a response containing an HTML page or document to the browser.
  • The basic processing steps for Java servlets are quite similar to the steps for CGI. However, the servlet runs a thread in the web container instead of in a separate OS process.
  • The web container itself is an OS process, but it does run as a service and is available continuously. This is opposed to a CGI script in which a new OS process (and shell) is created for each request.
  • The figure given below shows that a servlet executes as a thread within the web container’s process.
  • When the number of requests for a servlet rises, no additional instances of servlet or an OS processes are created.An each request is processed concurrently using one Java thread per request.

Advantages and Disadvantages of Java Servlets:

Servlets have the following advantages:

  • Each request is run separate thread, so servlet request processing is significantly faster than traditional CGI processing.
  • Servlet is scalable. Many more requests can be executed because the web container uses the thread rather than OS process, which is a limited system resource.
  • Servlets are robust and object oriented. You have all the capabilities of the Java programming language when you write the servlet, instead of capabilities of Perl or whatever language you use to write a CGI script.
  • Servlets can only be written in Java programming language, which makes them easy to write if you know the Java programming language. However, using servlet to generate pages with dynamic content requires application development expertise.
  • The servlets are platform independent, because, they are written in the Java programming language.
  • Servlets do have access to logging capabilities, most CGI programs do not.
  • The web container does provide additional services to the servlets, such as error handling and security.

Servlets have the following disadvantages:

  • Servlets often contain both business logic and presentation logic. Presentation logic is anything that controls how the application presents information to the user. Generating the HTML response within the servlet code is representation logic. Business logic is anything that manipulates data to accomplish something, such as storing data.
  • Concurrency issues must be handled by the servlets.

Mixing presentation logic and business logic means that whenever a web page changes (which can be monthly or weekly for many applications) the servlets must be rewritten, recompiled, and redeployed.

This disadvantage led to the development of template pages, including JavaServer Pages technology.

Using Separate Processes or Using Threads:

The following advantages result from running programs in separate processes instead of using threads:

  • Programs can be written in a variety of languages.
  • Web designers can easily reference programs that run in separate process.

The following advantages result from running servlet programs in threads instead of using other languages not in threads:

  • The CPU requirements are lower.
  • Java technologies separate processing code (business logic) from the HTML (presentation logic).
  • The Java programming language is robust and an object oriented.
  • The Java programming language is platform independent.

Sourabh Bhunje

Sourabh Bhunje, B.E. IT from Pune University. Currently Working at Techliebe. Professional Skills: Programming - Software & Mobile, Web & Graphic Design, Localization, Content Writing, Sub-Titling etc. http://techliebe.com/about-us

Leave a Reply