Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  SearchSearch  Latest imagesLatest images  RegisterRegister  Log in  

 

 Servlets

Go down 
AuthorMessage
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Servlets Empty
PostSubject: Servlets   Servlets EmptyTue Mar 06, 2007 1:14 pm

Overview
The Common Gateway Interface (CGI) was defined to allow Web servers to process user input and serve dynamic content. CGI programs can be developed in any script or programming language. But CGI also have certain drawbacks. Performance and scalability are big problems since a new process is created for each request, quickly draining a busy server of resources. Sharing resources such as database connections between scripts or multiple calls to the same script is far from trivial, leading to repeated execution of expensive operations.

Security is another big concern. Most Perl scripts use the command shell to execute OS commands with user-supplied data, for instance to send mail, search for information in a file, or just leverage OS commands in general. This use of a shell opens up many opportunities for a creative hacker to make the script remove all files on the server, mail the server's password file to a secret account, or do other bad things that the script writer didn't anticipate.

The Servlet API was developed to leverage the advantages of the Java platform to solve the issues of CGI and proprietary APIs. It's a simple API supported by virtually all Web servers and even load-balancing, fault-tolerant Application Servers. It solves the performance problem by executing all requests as threads in one process, or in a load-balanced system, in one process per server in the cluster.

Security is improved in many ways. First of all, you rarely need to let a shell execute commands with user-supplied data since the Java APIs provide access to all commonly used functions. You can use JavaMail to read and send email, Java Database Connect (JDBC) to access databases, the File class and related classes to access the file system, RMI, CORBA and Enterprise Java Beans (EJB) to access legacy systems. The Java security model makes it possible to implement fine-grained access controls, for instance only allowing access to a well-defined part of the file system.

The Servlet Run-time Environment
A servlet is a Java class and therefore needs to be executed in a Java VM by a service we call a servlet engine.
The servlet engine loads the servlet class the first time the servlet is requested, or optionally already when the servlet engine is started. The servlet then stays loaded to handle multiple requests until it is explicitly unloaded or the servlet engine is shut down.

All Servlet API classes and a simple servlet-enabled Web server are combined into the Java Servlet Development Kit (JSDK), available for download at Sun's official Servlet site

Servlet Interface and Life Cycle
A servlet is a Java class that implements the Servlet interface. This interface has three methods that define the servlet's life cycle:

public void init(ServletConfig config) throws ServletException
This method is called once when the servlet is loaded into the servlet engine, before the servlet is asked to process its first request.

public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
This method is called to process a request. It can be called zero, one or many times until the servlet is unloaded. Multiple threads (one per request) can execute this method in parallel so it must be thread safe.

public void destroy()
This method is called once just before the servlet is unloaded and taken out of service.
Back to top Go down
http://sojanctherakom.googlepages.com
 
Servlets
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: Programming Languages :: JAVA-
Jump to: