【正文】
ges quite well but need a helping hand to provide users with a customized, dynamic response. 大連交通大學(xué)信息工程學(xué)院 2020 屆本科生畢業(yè)設(shè)計(jì) (論文 )外文翻譯 14 DEFINITION:Static content on the Web es directly from text or data files, like HTML or JPEG files. These files might be changed from time to time, but they are not altered automatically when requested by a web browser. Dynamic content, on the other hand, is generated on the fly, typically in response to an individualized request from a browser. Common Gateway Interface (CGI): The first widely used standard for producing dynamic content was the Common Gateway Interface (CGI). CGI uses standard operating system features, such as environment variables and standard input and output, to create a bridge, or gateway, between the web server and other applications on the host machine. The other applications can look at the request sent to them by the web server and create a customized response. When a web server receives a request that’s intended for a CGI program, it runs that program and provides the program with information from the ining request. The CGI program runs and sends its output back to the server. The web server then relays the response to the browser. CGI defines a set of conventions regarding what information it will pass as environment variables and how it expects standard input and output to be used. Like HTTP, CGI is flexible and easy to implement, and a great number of CGIaware programs have been written. The main drawback to CGI is that it must run a new copy of the CGIaware program for each request. This is a relatively expensive process that can bog down highvolume sites where thousands of requests are serviced per minute. Another drawback is that CGI programs tend to be platform dependent. A CGI program written for one operating system may not run on another. Java servlets: Sun’s Java Servlet platform directly addresses the two main drawbacks of CGI , servlets offer better performance and utilization of resources than conventional CGI programs. Second, the writeonce, runanywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM). A servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications. The servlet itself is simply a Java class that has been piled into byte code, like any other Java object. The servlet has access to a rich API of HTTPspecific services, but it is still just another Java object running in an application and can leverage all your other Java assets. To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the servlet. 大連交通大學(xué)信息工程學(xué)院 2020 屆本科生畢業(yè)設(shè)計(jì) (論文 )外文翻譯 15 But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs. Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces, so that they can be shared between requests. Acquiring resources like these can take several seconds— which is longer than many surfers are willing to wait. The other edge of the sword is that, since servlets are multithreaded, servlet developers must take special care to be sure their servlets are threadsafe. To learn more about servlet programming, we remend Java Servlets by Example, by Alan R. Williamson [Williamson]. The definitive source for Servlet information is the Java Servlet Specification [Sun, JST]. JavaServer Pages: While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML. Code that looks like: (POne line of HTML./P)。 is all too mon in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more plex, Java developers end up being cast into the role of HTML page designers. Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize. To solve this problem, Sun turned to the idea of using server pages to bine scripting and templating technologies into a single ponent. To build Java Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP pages by looking for code that begins with % and ends with %. To be seen as a JSP page, the file just needs to be saved with an extension of .jsp. When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and piles the source into a Java class file— just as you would do if you were writing a servlet from scratch. At runtime, the cont