Вы находитесь на странице: 1из 4

Advantages of Servlets over CGI

Servlets are server side components that provides a powerful mechanism for developing server
web applications for server side. Earlier CGI was developed to provide server side capabilities to
the web applications. Although CGI played a major role in the explosion of the Internet, its
performance, scalability and reusability issues make it less than optimal solutions. Java Servlets
changes all that. Built from ground up using Sun's write once run anywhere technology java
servlets provide excellent framework for server side processing.
Using servlets web developers can create fast and efficient server side applications and can run it
on any servlet enabled web server. Servlet runs entirely inside the Java Virtual Machine. Since
the servlet runs on server side so it does not depend on browser compatibility.
Servlets have a number of advantages over CGI and other API's. They are:
1. Platform Independence
Servlets are written entirely in java so these are platform independent. Servlets can run on
any Servlet enabled web server. For example if you develop an web application in
windows machine running Java web server, you can easily run the same on apache web
server (if Apache Serve is installed) without modification or compilation of code.
Platform independency of servlets provide a great advantages over alternatives of
servlets.
2. Performance
Due to interpreted nature of java, programs written in java are slow. But the java servlets
runs very fast. These are due to the way servlets run on web server. For any program
initialization takes significant amount of time. But in case of servlets initialization takes
place first time it receives a request and remains in memory till times out or server shut
downs. After servlet is loaded, to handle a new request it simply creates a new thread and
runs service method of servlet. In comparison to traditional CGI scripts which creates a
new process to serve the request.
3. Extensibility
Java Servlets are developed in java which is robust, well-designed and object oriented
language which can be extended or polymorphed into new objects. So the java servlets
take all these advantages and can be extended from existing class to provide the ideal
solutions.
4. Safety
Java provides very good safety features like memory management, exception handling
etc. Servlets inherits all these features and emerged as a very powerful web server
extension.
5. Secure
Servlets are server side components, so it inherits the security provided by the web
server. Servlets are also benefited with Java Security Manager.



Introduction to Server Side
Programming

All of us (or most of us) would have started programming in Java with the ever famous ?Hello World!?
program. If you can recollect, we saved this file with a .java extension and later compiled the program
using javac and then executed the class file with java. Apart from introducing you to the language basics,
the point to be noted about this program is that ? ?It is a client side program?. This means that you write,
compile and also execute the program on a client machine (e.g. Your PC). No doubt, this is the easiest
and fastest way to write, compile and execute programs. But, it has little practical significance when it
comes to real world programming.
1. Why Server Side Programming?
2. Though it is technically feasible to implement almost any business logic using client
sideprograms, logically or functionally it carries no ground when it comes to enterprise
applications(e.g. banking, air ticketing, e-shopping etc.). To further explain, going by the client
side programming logic; a bank having 10,000 customers would mean that each customer should
have a copy of the program(s) in his or her PC which translates to 10,000 programs! In addition,
there are issues like security, resource pooling, concurrent access and manipulations to the
database which simply cannot be handled by client side programs. The answer to most of the
issues cited above is ? ?Server Side Programming?. Figure-1 illustrates Server side architecture
in the simplest terms.


3. Advantages of Server Side Programs

The list below highlights some of the important advantages of Server Side programs.
1. All programs reside in one machine called the Server. Any number of
remote machines(called clients) can access the server programs.
2. New functionalities to existing programs can be added at the server side which the
clients? can advantage without having to change anything from their side.
3. Migrating to newer versions, architectures, design patterns, adding patches, switching to
new databases can be done at the server side without having to bother about clients?
hardware or software capabilities.
4. Issues relating to enterprise applications like resource management, concurrency,
session management, security and performance are managed by service side
applications.
5. They are portable and possess the capability to generate dynamic and user-based
content (e.g. displaying transaction information of credit card or debit card depending on
user?s choice).

4. Types of Server Side Programs
1. Active Server Pages (ASP)
2. Java Servlets
3. Java Server Pages (JSPs)
4. Enterprise Java Beans (EJBs)
5. PHP
To summarize, the objective of server side programs is to centrally manage all
programs relating to a particular application (e.g. Banking, Insurance, e-shopping,
etc). Clients with bare minimum requirement (e.g. Pentium II, Windows XP
Professional, MS Internet Explorer and an internet connection) can experience the
power and performance of a Server (e.g. IBM Mainframe, Unix Server, etc) from a
remote location without having to compromise on security or speed. More
importantly, server programs are not only portable but also possess the capability to
generate dynamic responses based on user?s request.


Java Servlets are server side Java programs that require either a Web Server or an Application
Server for execution

Introduction to Java Servlets

Java Servlets are server side Javaprograms that require either a Web Server or an Application Server for
execution. Examples for Web Servers include Apache?s Tomcat Server and Macromedia?s JRun. Web
Servers include IBM?s Weblogic and BEA?s Websphere server. Examples for other Server programs
include Java Server Pages (JSPs) and Enterprise Java Beans (EJBs). In the forthcoming sections, we will
get acquainted with Servlet fundamentals and other associated information required for creating and
executing Java Servlets.
1. Basic Servlet Structure

As seen earlier, Java servlets are server side programs or to be more specific; web applications
that run on servers that comply HTTP protocol. The javax.servlet and javax.servlet.http packages
provide the necessary interfaces and classes to work with servlets. Servlets generally extend the
HttpServlet class and override the doGet or the doPost methods. In addition, other methods such
as init, service and destroy also called as life cycle methods might be used which will be
discussed in the following section. The skeleton of a servlet is given in Figure

Вам также может понравиться