1、 西安邮电 大学 毕 业 设 计(论 文) 外文文献翻译 院 (系) : 计算机 学院 专 业: 计算机科学与技术 班 级: 学生姓名: 导师姓名: 职称: 起止时间: 2011 年 9月 23日 至 2012年 6 月 2日 原文 : Java and the Internet Although Java is very useful for solving traditional stand-alone programming problems, it is also important because it will solve programming problems on the W
2、orld Wide Web. 1. Client-side programming The Webs initial server-browser design provided for interactive content, but the interactivity was completely provided by the server. The server produced static pages for the client browser, which would simply interpret and display them. Basic HTML contains
3、simple mechanisms for data gathering: text-entry boxes, check boxes, radio boxes, lists and drop-down lists, as well as a button that can only be programmed to reset the data on the form or “submit” the data on the form back to the server. This submission passes through the Common Gateway Interface
4、(CGI) provided on all Web servers. The text within the submission tells CGI what to do with it. The most common action is to run a program located on the server in a directory thats typically called “cgi-bin.” (If you watch the address window at the top of your browser when you push a button on a We
5、b page, you can sometimes see “cgi-bin” within all the gobbledygook there.) These programs can be written in most languages. Perl is a common choice because it is designed for text manipulation and is interpreted, so it can be installed on any server regardless of processor or operating system. Many
6、 powerful Web sites today are built strictly on CGI, and you can in fact do nearly anything with it. However, Web sites built on CGI programs can rapidly become overly complicated to maintain, and there is also the problem of response time. The response of a CGI program depends on how much data must
7、 be sent, as well as the load on both the server and the Internet. (On top of this, starting a CGI program tends to be slow.) The initial designers of the Web did not foresee how rapidly this bandwidth would be exhausted for the kinds of applications people developed. For example, any sort of dynami
8、c graphing is nearly impossible to perform with consistency because a GIF file must be created and moved from the server to the client for each version of the graph. And youve no doubt had direct experience with something as simple as validating the data on an input form. You press the submit button
9、 on a page; the data is shipped back to the server; the server starts a CGI program that discovers an error, formats an HTML page informing you of the error, and then sends the page back to you; you must then back up a page and try again. Not only is this slow, its inelegant. The solution is client-
10、side programming. Most machines that run Web browsers are powerful engines capable of doing vast work, and with the original static HTML approach they are sitting there, just idly waiting for the server to dish up the next page. Client-side programming means that the Web browser is harnessed to do w
11、hatever work it can, and the result for the user is a much speedier and more interactive experience at your Web site. The problem with discussions of client-side programming is that they arent very different from discussions of programming in general. The parameters are almost the same, but the plat
12、form is different: a Web browser is like a limited operating system. In the end, you must still program, and this accounts for the dizzying array of problems and solutions produced by client-side programming. The rest of this section provides an overview of the issues and approaches in client-side p
13、rogramming. 2.Plug-ins One of the most significant steps forward in client-side programming is the development of the plug-in. This is a way for a programmer to add new functionality to the browser by downloading a piece of code that plugs itself into the appropriate spot in the browser. It tells th
14、e browser “from now on you can perform this new activity.” (You need to download the plug-in only once.) Some fast and powerful behavior is added to browsers via plug-ins, but writing a plug-in is not a trivial task, and isnt something youd want to do as part of the process of building a particular
15、site. The value of the plug-in for client-side programming is that it allows an expert programmer to develop a new language and add that language to a browser without the permission of the browser manufacturer. Thus, plug-ins provide a “back door” that allows the creation of new client-side programm
16、ing languages (although not all languages are implemented as plug-ins). 3.Scripting languages Plug-ins resulted in an explosion of scripting languages. With a scripting language you embed the source code for your client-side program directly into the HTML page, and the plug-in that interprets that l
17、anguage is automatically activated while the HTML page is being displayed. Scripting languages tend to be reasonably easy to understand and, because they are simply text that is part of an HTML page, they load very quickly as part of the single server hit required to procure that page. The trade-off
18、 is that your code is exposed for everyone to see (and steal). Generally, however, you arent doing amazingly sophisticated things with scripting languages so this is not too much of a hardship. This points out that the scripting languages used inside Web browsers are really intended to solve specifi
19、c types of problems, primarily the creation of richer and more interactive graphical user interfaces (GUIs). However, a scripting language might solve 80 percent of the problems encountered in client-side programming. Your problems might very well fit completely within that 80 percent, and since scr
20、ipting languages can allow easier and faster development, you should probably consider a scripting language before looking at a more involved solution such as Java or ActiveX programming. The most commonly discussed browser scripting languages are JavaScript (which has nothing to do with Java; its n
21、amed that way just to grab some of Javas marketing momentum), VBScript (which looks like Visual Basic), and Tcl/Tk, which comes from the popular cross-platform GUI-building language. There are others out there, and no doubt more in development. JavaScript is probably the most commonly supported. It
22、comes built into both Netscape Navigator and the Microsoft Internet Explorer (IE). In addition, there are probably more JavaScript books available than there are for the other browser languages, and some tools automatically create pages using JavaScript. However, if youre already fluent in Visual Ba
23、sic or Tcl/Tk, youll be more productive using those scripting languages rather than learning a new one. (Youll have your hands full dealing with the Web issues already.) 4.Java If a scripting language can solve 80 percent of the client-side programming problems, what about the other 20 percentthe “r
24、eally hard stuff?” The most popular solution today is Java. Not only is it a powerful programming language built to be secure, cross-platform, and international, but Java is being continually extended to provide language features and libraries that elegantly handle problems that are difficult in tra
25、ditional programming languages, such as multithreading, database access, network programming, and distributed computing. Java allows client-side programming via the applet. An applet is a mini-program that will run only under a Web browser. The applet is downloaded automatically as part of a Web pag
26、e (just as, for example, a graphic is automatically downloaded). When the applet is activated it executes a program. This is part of its beautyit provides you with a way to automatically distribute the client software from the server at the time the user needs the client software, and no sooner. The
27、 user gets the latest version of the client software without fail and without difficult reinstallation. Because of the way Java is designed, the programmer needs to create only a single program, and that program automatically works with all computers that have browsers with built-in Java interpreter
28、s. (This safely includes the vast majority of machines.) Since Java is a full-fledged programming language, you can do as much work as possible on the client before and after making requests of the server. For example, you wont need to send a request form across the Internet to discover that youve g
29、otten a date or some other parameter wrong, and your client computer can quickly do the work of plotting data instead of waiting for the server to make a plot and ship a graphic image back to you. Not only do you get the immediate win of speed and responsiveness, but the general network traffic and
30、load on servers can be reduced, preventing the entire Internet from slowing down. One advantage a Java applet has over a scripted program is that its in compiled form, so the source code isnt available to the client. On the other hand, a Java applet can be decompiled without too much trouble, but hi
31、ding your code is often not an important issue. Two other factors can be important. As you will see later in this book, a compiled Java applet can comprise many modules and take multiple server “hits” (accesses) to download. (In Java 1.1 and higher this is minimized by Java archives, called JAR file
32、s, that allow all the required modules to be packaged together and compressed for a single download.) A scripted program will just be integrated into the Web page as part of its text (and will generally be smaller and reduce server hits). This could be important to the responsiveness of your Web sit
33、e. Another factor is the all-important learning curve. Regardless of what youve heard, Java is not a trivial language to learn. If youre a Visual Basic programmer, moving to VBScript will be your fastest solution, and since it will probably solve most typical client/server problems you might be hard
34、 pressed to justify learning Java. If youre experienced with a scripting language you will certainly benefit from looking at JavaScript or VBScript before committing to Java, since they might fit your needs handily and youll be more productive sooner.to run its applets withi 5.ActiveX To some degree
35、, the competitor to Java is Microsofts ActiveX, although it takes a completely different approach. ActiveX was originally a Windows-only solution, although it is now being developed via an independent consortium to become cross-platform. Effectively, ActiveX says “if your program connects to its env
36、ironment just so, it can be dropped into a Web page and run under a browser that supports ActiveX.” (IE directly supports ActiveX and Netscape does so using a plug-in.) Thus, ActiveX does not constrain you to a particular language. If, for example, youre already an experienced Windows programmer usi
37、ng a language such as C+, Visual Basic, or Borlands Delphi, you can create ActiveX components with almost no changes to your programming knowledge. ActiveX also provides a path for the use of legacy code in your Web pages. 6.Internet vs. intranet The Web is the most general solution to the client/se
38、rver problem, so it makes sense that you can use the same technology to solve a subset of the problem, in particular the classic client/server problem within a company. With traditional client/server approaches you have the problem of multiple types of client computers, as well as the difficulty of
39、installing new client software, both of which are handily solved with Web browsers and client-side programming. When Web technology is used for an information network that is restricted to a particular company, it is referred to as an intranet. Intranets provide much greater security than the Intern
40、et, since you can physically control access to the servers within your company. In terms of training, it seems that once people understand the general concept of a browser its much easier for them to deal with differences in the way pages and applets look, so the learning curve for new kinds of syst
41、ems seems to be reduced. The security problem brings us to one of the divisions that seems to be automatically forming in the world of client-side programming. If your program is running on the Internet, you dont know what platform it will be working under, and you want to be extra careful that you
42、dont disseminate buggy code. You need something cross-platform and secure, like a scripting language or Java. If youre running on an intranet, you might have a different set of constraints. Its not uncommon that your machines could all be Intel/Windows platforms. On an intranet, youre responsible fo
43、r the quality of your own code and can repair bugs when theyre discovered. In addition, you might already have a body of legacy code that youve been using in a more traditional client/server approach, whereby you must physically install client programs every time you do an upgrade. The time wasted i
44、n installing upgrades is the most compelling reason to move to browsers, because upgrades are invisible and automatic. If you are involved in such an intranet, the most sensible approach to take is the shortest path that allows you to use your existing code base, rather than trying to recode your pr
45、ograms in a new language. When faced with this bewildering array of solutions to the client-side programming problem, the best plan of attack is a cost-benefit analysis. Consider the constraints of your problem and what would be the shortest path to your solution. Since client-side programming is st
46、ill programming, its always a good idea to take the fastest development approach for your particular situation. This is an aggressive stance to prepare for inevitable encounters with the problems of program development. 翻译: Java和因特网 Java 除了可解决传统的程序设计问题以外,还能解决 World Wide Web(万维网 )上的编程问题。 1.客户端编程 Web最
47、初采用的 “服务器浏览器 ”方案可提供交互式内容,但这种交互能力完全由服务器提供,为服务器和因特网带来了不小的负担。服务器一般为客户浏览器产生静态网页,由后者简单地解释并显示出来。基本 HTML 语言提供了简单的数据收集机制:文字输入框、复选框、单选钮、列表以及下拉列表等,另外还有一个按钮,只能由程序规定重新设置表单中的数据,以便回传给服务器。用户提交的信息通过所有Web服务器均能支持的 “通用网关接口 ”( CGI)回传到服务器。包含在提交数据中的文字指示 CGI 该如何操作。最常见的行动是运行位于服务器的一个程序。那个程序一般保存在一个名为 “cgi-bin”的目录中(按下 Web页内的一
48、个按钮时,请注意一下浏览器顶部的地址窗,经常都能发现 “cgi-bin”的字样)。大多数语言都可用来编制这些程序,但其 中最常见的是 Perl。这是由于 Perl是专为文字的处理及解释而设计的,所以能在任何服务器上安装和使用,无论采用的处理器或操作系统是什么。 2. 插件 朝客户端编程迈进的时候,最重要的一个问题就是插件的设计。利用插件,程序员可以方便地为浏览器添加新功能,用户只需下载一些代码,把它们 “插入 ”浏览器的适当位置即可。这些代码的作用是告诉浏览器 “从现在开始,你可以进行这些新活动了 ”(仅需下载这些插入一次)。有些快速和功能强大的行为是通过插件添加到浏览器的。但插件的编写并不是
49、一件简单的任务。在我们构建一个特定的站点时, 可能并不希望涉及这方面的工作。对客户端程序设计来说,插件的价值在于它允许专业程序员设计出一种新的语言,并将那种语言添加到浏览器,同时不必经过浏览器原创者的许可。由此可以看出,插件实际是浏览器的一个 “后门 ”,允许创建新的客户端程序设计语言(尽管并非所有语言都是作为插件实现的)。 3. 脚本编制语言 插件造成了脚本编制语言的爆炸性增长。通过这种脚本语言,可将用于自己客户端程序的源码直接插入 HTML页,而对那种语言进行解释的插件会在 HTML页显示的时候自动激活。脚本语言一般都倾向于尽量简化,易于理解。而且由于它们 是从属于 HTML 页的一些简单正文,所以只需向服务器发出对那个页的一次请求,即可非常快地载入。缺点是我们的代码全部暴露在人们面前。另一方面,由于通常不用脚本编制语言做 过分 复杂的事情,所以这个问题暂且可以放在一边。 脚本语言真正面向的是特定类型问题的解决,其中主要涉