Java Tutorial - Java Script :
Defining Architectural Pieces
In a Web-based application, the Web server receives HTTP requests. The browser creates the HTTP request and directs it to a server based on a Uniform Resource Locator (URL). When the Web server receives the request from the browser, it then determines how to respond to the request (see Figure 5.1). If the request is for a file then the Web server returns that file. This is the way that most static HTML files are handled. However, there is an alternate method of handling requests: the request may be to execute a program that will, in turn, generate the response. The Web server executes that program, and the program then generates the response for the request. The response generated is often an HTML text, but it could also be an XML document, an image, or anything else that can be transferred through HTTP.
One popular technology for these Web-server-executed programs is known as CGI (Common Gateway Interface). When a CGI program is requested through a URL, the Web server launches and executes the program to generate the response. CGI programs can be written in almost any language, including
Perl, Java, and C/C++. Each time a request is made for a CGI program, a new process is created and the program must be initialized. Initialization can be a time-consuming process that may include establishing database connections and/or reading in files and other tasks that need to be repeated each time the program is started.
Java has replaced CGI programs with Java servlets. Servlets, a key element in enterprise Java, provide a means of creating dynamically generated Web pages, Web pages that respond to user input and control. Aservlet is typically used to dynamically generate a response for an HTTP request. For example, if a user enters a city and state into a Web form to look for a hotel, a servlet might be used to generate the list of hotels within the specified city. This list is then dynamically created and returned to the browser based on the user’s input of city and state. Servlets run within a servlet container; that is, a servlet container acts as a host for Java servlets and manages the life cycle of
those servlets. Servlet containers (sometimes called engines) are a standard component in the J2EE architecture. Most servlet containers are designed so that they can be integrated with an existing Web server. However, many servlet containers can also be configured to behave as Web servers themselves. This configuration is often
preferable for development environments because it is easier to configure and maintain. It is possible to create very complex applications using just servlets. This is common for what we call “Web applications.” These applications are just that, Web applications with little or no integration with the rest of the enterprise. By contrast, in a full-scale enterprise architecture, the Web server and servlet container work together in the front end of an enterprise architecture and form the Web tier (see Figure 5.2). The Web-tier is responsible for most of the user interface generation and delivery (the browser renders the user interface). The Wetier handles HTTP communication between the applications and the browsers or agents.
