【正文】
it does not use a shell to do so. And, of course, array bounds checking and other memory protection features are a central part of the Java programming language. 7. Mainstream There are a lot of good technologies out there. But if vendors don39。ll only be discussing HTTP servlets. The Advantages of Servlets Over Traditional CGI Java servlets are more efficient, easier to use, more powerful, more portable, safer, and cheaper than traditional CGI and many alternative CGIlike technologies. 1. Efficient With traditional CGI, a new process is started for each HTTP request. If the CGI program itself is relatively short, the overhead of starting the process can dominate the execution time. With servlets, the Java virtual machine stays running and handles each request with a lightweight Java thread, not a heavyweight operating system process. Similarly, in traditional CGI, if there are N requests to the same CGI program, the code for the CGI program is loaded into memory N times. With servlets, however, there would be N threads, but only a single copy of the servlet class would be loaded. This approach reduces server memory requirements and saves time by instantiating fewer objects. Finally, when a CGI program finishes handling a request, the progra m terminates. This approach makes it difficult to cache putations, keep database connections open, and perform other optimizations that rely on persistent data. Servlets, however, remain in memory even after they plete a response, so it is straightforward to store arbitrarily plex data between client requests. 2. Convenient Servlets have an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions, and many other such highlevel utilities. In CGI, you have to do much of this yourself. Besides, if you already know the Java programming language, why learn Perl too? You39。t know what to display until you read the data that the user submits. Just remember that the user submits two kinds of data: explicit (., HTML form data) and implicit (., HTTP request headers). Either kind of input can be used to build the output page. In particular, it is quite mon to build a userspecific page based on a cookie value. 2. The Web page is derived from data that changes frequently. If the page changes for every request, then you certainly need to build the response at request time. If it changes only periodically, however, you could do it two ways: you could periodically build a new Web page on the server (independently of client requests), or you could wait and only build the page when the user requests it. The right approach depends on the situation, but sometimes it is more convenient to do the latter: wait for the user request. For example, a weather report or news headlines site might build the pages dynamically, perhaps returning a previously built page if that page is still up to date. 3. The Web page uses information from corporate databases or other serverside sources. If the information is in a database, you need serverside processing even if the client is using dynamic Web content such as an applet. Imagine using an applet by itself for a search engine site: Downloading 50 terabyte applet, please wait! Obviously, that is silly。t speak HTTP or return results in HTML, so the Web browser can39。An Overview of Servlet and JSP Technology Gildas Avoine and Philippe Oechslin EPFL, Lausanne, Switzerland A Servlet39。s Job Servlets are Java programs that run on Web or application servers, acting as a middle layer between requests ing from Web browsers or other HTTP clients and databases or applications on the HTTP server. Their job is to