




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Java and the InternetIf Java is, in fact, yet another computer programming language, you may question why it is so important and why it is being promoted as a revolutionary step in computer programming. The answer isnt immediately obvious if youre coming from a traditional programming perspective. A
2、lthough Java is very useful for solving traditional standalone programming problems, it is also important because it will solve programming problems on the World Wide Web.What is the Web?The Web can seem a bit of a mystery at first, with all this talk of “surfing, “presence, and “home pages. Its hel
3、pful to step back and see what it really is, but to do this you must understand client/server systems, another aspect of computing thats full of confusing issues.Client/Server computingThe primary idea of a client/server system is that you have a central repository of informationsome kind of data, o
4、ften in a databasethat you want to distribute on demand to some set of people or machines. A key to the client/server concept is that the repository of information is centrally located so that it can be changed and so that those changes will propagate out to the information consumers. Taken together
5、, the information repository, the software that distributes the information and the machine where the information and software reside is called the server. The software that resides on the remote machine, communicates with the server, fetches the information, processes it, and then displays it on th
6、e remote machine is called the client.The basic concept of client/server computing, then, is not so complicated. The problems arise because you have a single server trying to serve many clients at once. Generally, a database management system is involved, so the designer “balances the layout of data
7、 into tables for optimal use. In addition, systems often allow a client to insert new information into a server. This means you must ensure that one clients new data doesnt walk over another clients new data, or that data isnt lost in the process of adding it to the database (this is called transact
8、ion processing). As client software changes, it must be built, debugged, and installed on the client machines, which turns out to be more complicated and expensive than you might think. Its especially problematic to support multiple types of computers and operating systems. Finally, theres the all-i
9、mportant performance issue: You might have hundreds of clients making requests of your server at any one time, so any small delay is crucial. To minimize latency, programmers work hard to offload processing tasks, often to the client machine, but sometimes to other machines at the server site, using
10、 so-called middleware. (Middleware is also used to improve maintainability.)The simple idea of distributing information has so many layers of complexity that the whole problem can seem hopelessly enigmatic. And yet its crucial: Client/server computing accounts for roughly half of all programming act
11、ivities. Its responsible for everything from taking orders and credit-card transactions to the distribution of any kind of datastock market, scientific, government, you name it. What weve come up with in the past is individual solutions to individual problems, inventing a new solution each time. The
12、se were hard to create and hard to use, and the user had to learn a new interface for each one. The entire client/server problem needs to be solved in a big way.The Web as a giant serverThe Web is actually one giant client/server system. Its a bit worse than that, since you have all the servers and
13、clients coexisting on a single network at once. You dont need to know that, because all you care about is connecting to and interacting with one server at a time (even though you might be hopping around the world in your search for the correct server).Initially it was a simple one-way process. You m
14、ade a request of a server and it handed you a file, which your machines browser software (i.e., the client) would interpret by formatting onto your local machine. But in short order people began wanting to do more than just deliver pages from a server. They wanted full client/server capability so th
15、at the client could feed information back to the server, for example, to do database lookups on the server, to add new information to the server, or to place an order (which required more security than the original systems offered). These are the changes weve been seeing in the development of the We
16、b.The Web browser was a big step forward: the concept that one piece of information could be displayed on any type of computer without change. However, browsers were still rather primitive and rapidly bogged down by the demands placed on them. They werent particularly interactive, and tended to clog
17、 up both the server and the Internet because any time you needed to do something that required programming you had to send information back to the server to be processed. It could take many seconds or minutes to find out you had misspelled something in your request. Since the browser was just a view
18、er it couldnt perform even the simplest computing tasks. (On the other hand, it was safe, because it couldnt execute any programs on your local machine that might contain bugs or viruses.)To solve this problem, different approaches have been taken. To begin with, graphics standards have been enhance
19、d to allow better animation and video within browsers. The remainder of the problem can be solved only by incorporating the ability to run programs on the client end, under the browser. This is called client-side programming.Client-side programmingThe Webs initial server-browser design provided for
20、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 HyperText Markup Language (HTML) contains simple mechanisms for data gathering: text-entry boxes, check boxe
21、s, 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 (CGI) provided on all Web servers. The text within the submission t
22、ells 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 Web page, you can sometimes see “cgi-bin within all the gobbledygook t
23、here.) These programs can be written in most languages. Perl has been 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. However, Python (my favoritesee P) has been making inroads
24、 because of its greater power and simplicity.Many powerful Web sites today are built strictly on CGI, and you can in fact do nearly anything with CGI. However, Web sites built on CGI programs can rapidly become overly complicated to maintain, and there is also the problem of response time. The respo
25、nse of a CGI program depends on how much data must 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
26、 people developed. For example, any sort of dynamic graphing is nearly impossible to perform with consistency because a Graphics Interchange Format (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 somethin
27、g as simple as validating the data on an input form. You press the submit button 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 p
28、age and try again. Not only is this slow, its inelegant.The solution is client-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 nex
29、t page. Client-side programming means that the Web browser is harnessed to do whatever 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 discussio
30、ns of programming in general. The parameters are almost the same, but the platform 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 t
31、his section provides an overview of the issues and approaches in client-side programming.Plug-insOne 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 co
32、de that plugs itself into the appropriate spot in the browser. It tells the 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 s
33、omething youd want to do as part of the process of building a particular 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 p
34、rovide a “back door that allows the creation of new client-side programming languages (although not all languages are implemented as plug-ins).Scripting languagesPlug-ins resulted in an explosion of scripting languages. With a scripting language, you embed the source code for your client-side progra
35、m directly into the HTML page, and the plug-in that interprets that language 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
36、of the single server hit required to procure that page. The trade-off 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 la
37、nguages used inside Web browsers are really intended to solve specific 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
38、 might very well fit completely within that 80 percent, and since scripting 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 scriptin
39、g languages are JavaScript (which has nothing to do with Java; its named 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
40、development.JavaScript is probably the most commonly supported. It comes built into both Netscape Navigator and the Microsoft Internet Explorer (IE). Unfortunately, the flavor of JavaScript on the two browsers can vary widely (the Mozilla browser, freely downloadable from M, supports the E
41、CMAScript standard, which may one day become universally supported). 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 BASIC or Tcl/Tk,
42、 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.) 原文来源:(美)Bruce Ecket. Thinking in JAVA第三版. 2003 Java 和Internet可能你会问,如果Java只是一种新的计算机编程语言的话实际上这话也没错,它为什么会那么重要,为什么会被除数拔高到“计算机编程领域的革命
43、性的进步,这个高度。如果你是从传统编程的立场上来看这个问题,也许答案还不是那么有说服力。尽管在解决传统的,孤立的编程问题方面,Java也是很能干的,但是真正让它脱颖而出的,是因为它能解决在万维网上编程的问题。Web就什么?刚开始的时候,Web看上去很神秘,大家都江堰市在谈冲浪、在线、主页什么的。要把讲Web讲清楚,最好是退回来从头开始。但是这么做,先得理解客户/效劳器系统。这是计算机技术的另一个领域,里面也有大把让人头晕的问题。客户/效劳器系统客户机/效劳器系统的主要思想是,你有一个中央信息库通常是保存在数据库中的一些信息要根据需要,把它们分配给某些人或机器。客户机/效劳器系统的关键在于,信息
44、库会集中管理信息,因此信息的修改能够传播到用户那里。信息库,分发信息的软件,以及存储信息的软件的机器合起来称为效劳器。存储在远程机器上的软件会同这个效劳器通讯,提取信息,处理信息,并且在过程机器上显示结果。这被除数称为客户。这么看来,客户/效劳器计算机的根本概念没那么复杂。但是,当你试图用孤零零的一个效劳器来为很多客户效劳的时候,问题就来了。这个架构通常都会牵扯到数据库管理系统,所以为了优化应用,设计人员会去“平衡数据的格式。此外,通常系统还允许客户往效劳器里插入新的数据。这就意味着你必须保证一个客户的新数据不会和另一个客户的新数据搅在一起,以及数据不会在添加的过程中遗失这被称为事务处理。当客
45、户端的程序修改之后,还必须重新编译,调试并且安装到客户机上,这要比你想像的复杂昂贵得多。而且如果要支持多种机器或操作系统的话,事情会更麻烦。最后还有一个最重要的性能问题:效劳器可能会同时响应成百上千个客户,所以再小的耽误都是很要命的。为了把延时降到最低,程序员们尽量减轻效劳的负载,通常会把这些处理任务挪到客户端,不过有时也会移到所谓的中间件的效劳器上。中间件也被用来增进系统的可维护性。分发数据这个简单的思想竟然会引出这么些复杂层次,而所有这些问题看起来都像是根本不可能解开的谜。但还有更重要的:大约有一半的开发工程都是基于客户/效劳器架构的。它们包括像接收订单,信用卡交易额以及分发各种各样的数据
46、股票市场的,科研的,政府部门的,只要你能叫的上名字的。以前我们的作法是为每个问题设计不同的解决方案,每次都创造一种新方法。这种工程开发起来难,用户用起来也不方便,它们必须适应新的界面。客户/效劳器架构这个问题必须要能在总体上解决。把Web当作巨型的效劳器Web实际上就是一个巨型的客户/效劳器系统。实际上还差一点,因为所有的效劳器和客户机是共存在同一个网络上的。不过这点你并不知道,因为你只关心是不是能连到那台效劳器,并且对它进行操作尽管你可能得先在什么地方找到那台效劳器。最初这只是个关向过程。你向效劳器提请求,它交给你一个文件,然后你用本地机上的浏览器也就是客户来解释这个文件并且为它重新排版。但
47、没过多久,人们就不满足于仅仅从效劳器收发文件了。他们需要完整的客户/效劳器功能,所以客户也能向效劳器发送信息了,比方查询效劳器端的数据库,向效劳器添加新的信息,或者下单这项任务所要求的平安性比系统原先能提供的要高得多。这些就是我们在Web的开展历程中亲眼目睹的变化。Web浏览器是一项巨大的进步:它的思想是要让同样的信息以通常的形式显示在所有的机器上。然而浏览器还是太原始了一些,而且也很快被加在它身上的任务给拖垮了。它的互动性不好,而且所有需要编程解决的任务都要交到效劳器上去处理,所以经常会把效劳器和Internet给堵了。有时可能会花几秒钟,甚至是几分钟,才会发现提交的请求里面有一个拼写错误。
48、由于浏览器只是用来显示,不能承当哪怕是最简单的计算任务。另一方面这样也很平安,因为它不会在你的本地机上执行可能包含bug或病毒程序。为了解决这个问题,人们用了很多方法。开始是升级图形超标准,让浏览器能显示效果更佳的动画和视频。但是有些问题,只能通过让客户端的浏览器运行程序来解决了。这被称为客户端编程。 客户端编程Web最初的效劳器浏览器设计提供了互动内容,但是这种互动性是完全建立在效劳器之上的。效劳器为客户端提供静态页面,而浏览器只是简单的解释页面,然后显示出来。HTML包括了根本的数据采集功能:输入框,复选框,单项选择按钮,列表,下拉式列表,以及只能用于去除表单或是把表单数据“提交给效劳器的按扭。提交上来的数据会交给Web效劳器上的通用网关接口程序。这些文本会告诉CGI该做些什么。最常见的就是在效劳器上运行一个程序,这个程序一般会放在“cgi-bin目录中。如果按完Web页面上的按扭之后,你仔细观察浏览器顶部的地址条的话,有时你就会在那些不知所云的东西中看到“cgi-bin。大多数语言都可以写这些程序。Perl是最常用的,因为它设计的目的就是为了处理和解释文本,所以不管效劳器用的是那种处理器,或是那种操作系统,都能安装Perl。但Python我的最爱见 P由于其功能强大简单易用,已经对Perl的霸主地位发
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 1.1 科学并不神秘 说课稿 -2024-2025学年浙教版七年级上册科学
- 2025年专业美容院化妆区装饰装修施工服务合同
- 2025年度云计算数据中心网络安全防护解决方案合作协议数据堡垒
- 2025年度音乐MV演员培训与聘用合同协议
- 2025年学历类自考行政组织理论-资产评估参考题库含答案解析(5套试卷)
- 2025年智能叉车租赁与综合保险方案合同样本
- 2025年学历类自考行政管理学-金融理论与实务参考题库含答案解析(5套试卷)
- 2025年知识产权财产保全申请合同范本及操作手册
- 2025年智能驾驶车辆租赁服务及违约责任解除协议
- 2025年新型节能建筑材料供应与服务框架合同
- 2025秋开学典礼 校长引用电影《长安的荔枝》讲话:荔枝尚早,路正长远-在时光中奔跑,用行动送达自己的“长安”
- 中级经济师模拟试题及答案
- 家庭食品卫生知识培训课件
- 无人机应用技术培训教材
- 地铁安保培训课件
- 2025年广西南宁职业技术大学招聘教职人员考试笔试试题(含答案)
- 2025年食品安全监督员专业技能考核试题及答案解析
- 企业微信办公使用教程
- 红十字应急救护创伤止血
- 2025-2026学年高二上学期开学入学教育主题班会【课件】
- 学堂在线 大学历史与文化 章节测试答案
评论
0/150
提交评论