Now let's think about how to create an application that works in a real-world web environment, and it will take the advantage of Java to the fullest. Part of this application is a Java program that runs on a Web server, and the other part is a "patch" or "applet" that downloads from the server to the browser (that is, "customer"). This piece of the program collects information from the user and passes it back to the application running on the Web server. The task of the program is very simple: The program will ask the user's e-mail address, and after verifying that the address is qualified (no spaces, and there is an @ symbol), send the e-mail to the Web server. The program running on the server captures the returned data and checks for a data file that contains all the e-mail addresses. If the address is already contained in a file, feedback a message to the browser explaining the situation. The message is displayed by the program slice. If a new address is placed, place it in the list and notify the tablet that the e-mail address has been successfully added.
To solve this problem in a traditional way, we want to create an HTML page that contains a text field and a Submit button. Users can type any content they like in a text field and submit it to the server without hindrance (no checks are done on the client). While submitting the data, the Web page also tells the server what to do with the data--knowing the Common Gateway Interface (CGI) program, and then running the server immediately after receiving the data. This CGI program is usually written in Perl or C (sometimes in C + + but requires server support) and must be able to control everything that might happen. It first checks the data to see if the correct format is used. If the answer is no, then the CGI program must create an HTML page to describe the problems encountered. This page is forwarded to the server, which is then fed back to the user. After the user sees the error prompt, he or she must try to submit it again until it is passed. If the data is correct, the CGI program opens the data file, either by adding the e-mail address to the file or by stating that the address is already in the data file. In either case, you must format an appropriate HTML page so that the server can return it to the user.
As a Java programmer, the solution to this problem is very clumsy. And naturally, we want all the work done in Java. First, we will use a Java program to take care of the client's data validation, to avoid data transmission between the server and customers, wasting time and bandwidth, while reducing the burden of the server to build additional HTML pages. Then skip the Perl CGI script and replace it with a Java application running on the server. In fact, we've completely skipped the Web server here, and just need to establish a connection between the program slices and the Java applications running on the server.
As you will soon experience, although it looks very simple, there are actually some unexpected problems that make the situation a little bit more complicated. Writing a program in Java 1.1 is ideal, but it often doesn't work. By the time the book was written, there were still a handful of browsers with Java 1.1 capabilities, and even though such browsers were now very popular, there was still a need to consider taking care of those who were slow to upgrade. So from a security standpoint, the code for the program is best written in Java 1.0. Based on this premise, we cannot combine (compress) the. class file in the program slice with a jar file. Therefore, we should reduce the number of use of. class files as much as possible to shorten the download time.
OK, and then I use the Web server (which is used to write this demo program). It does support Java, but is limited to Java 1.0! Therefore, server applications must also be written in Java 1.0.