Chapter 2: Web Applications: Servlets, JSPs, and More
Chapter 2: Web Applications: Servlets, JSPs, and More A URL for a CGI program looks something like this fictitious URL: http://www.myserver.com/cgi-bin/MyExecutable?name1=value1&name2=value2 The first part of the URL is the protocol name (in this case HTTP), followed by the name of the server. Everything after this and before the question mark is the context path. The /cgi-bin/ part of the URL alerts the server that it should execute the CGI program specified in the next part of the URL, in this case MyExecutable. The section after the question mark is known as the query string, and it enables the client to send information to the CGI program. In this way, the program can run with client-specific information affecting the results. CGI suffered from several drawbacks: . Each incoming CGI request required starting an operating system process. . This process would then load and run a (CGI) program. . Tedious and repetitive coding was needed to handle the network protocol and request decoding. The first two operations in the previous list can use a large number of CPU cycles and a lot of memory. Because both operations must be performed for each request, a server machine could get overloaded if too many requests arrive in a short period of time. Also, because each CGI program is independent of the other, and often in incompatible programming languages, it is not possible to share code used in networking and request decoding. Note that CGI describes only the contract between the Web server and the program. No services are provided to help implement user-centric systems. Thus it is hard to do things such as maintain the identity of the client across requests, restrict access to the application to authorized users, and store runtime information in the application. For this reason, CGI scripts are not used by most modern Web sites. You might still come across some being used for simple tasks such as processing forms. Hence, it became necessary to provide a framework for building Web applications. This framework would provide the services mentioned previously, in addition to solving the problem of poor performance and scalability. Server Side Java: Servlets Servlets are portions of logic written in Java that have a defined form and are invoked to dynamically generate content or perform some action. Servlets overcome the problems mentioned earlier with CGI programs, such as the following: . The overhead of starting an operating system process for each request is eliminated. A Java virtual machine (JVM) is kept running, and all requests are handled by that JVM. . Java classes are loaded by the JVM to process incoming requests; if more than one request requires the same processing, the already loaded class can be used to handle it. This eliminates the class loading overhead for all but the first request.
For reliable and cheap web hosting services please check javaweb hosting website.