[ Pobierz całość w formacie PDF ]
.And you ve no doubt had direct experience with something assimple as validating the data on an input form.You press the submit button on a page; thedata 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 sends the page back to you; youmust then back up a page and try again.Not only is this slow, it s not elegant.The solution is client-side programming.Most machines that run Web browsers arepowerful engines capable of doing vast work, and with the original static HTML approachthey are sitting there, just idly waiting for the server to dish up the next page.Client-sideprogramming means that the Web browser is harnessed to do whatever work it can, and theresult for the user is a much speedier and more interactive experience at your Web site.8The material in this section is adapted from an article by the author that originally appeared onMainspring, at www.mainspring.com.Used with permission.Chapter 1: Introduction to Objects 59 The problem with discussions of client-side programming is that they aren t very differentfrom discussions of programming in general.The parameters are almost the same, but theplatform is different: a Web browser is like a limited operating system.In the end, it s stillprogramming and this accounts for the dizzying array of problems and solutions producedby client-side programming.The rest of this section provides an overview of the issues andapproaches in client-side programming.Plug-insOne of the most significant steps forward in client-side programming is the development ofthe plug-in.This is a way for a programmer to add new functionality to the browser bydownloading a piece of code that plugs itself into the appropriate spot in the browser.It tellsthe browser  from now on you can perform this new activity. (You need to download theplug-in only once.) Some fast and powerful behavior is added to browsers via plug-ins, butwriting a plug-in is not a trivial task and isn t something you d want to do as part of theprocess of building a particular site.The value of the plug-in for client-side programming isthat it allows an expert programmer to develop a new language and add that language to abrowser without the permission of the browser manufacturer.Thus, plug-ins provide the backdoor that allows the creation of new client-side programming languages (although not alllanguages are implemented as plug-ins).Scripting languagesPlug-ins resulted in an explosion of scripting languages.With a scripting language youembed the source code for your client-side program directly into the HTML page and theplug-in that interprets that language is automatically activated while the HTML page isbeing displayed.Scripting languages tend to be reasonably simple to understand, andbecause they are simply text that is part of an HTML page they load very quickly as part ofthe single server hit required to procure that page.The trade-off is that your code is exposedfor everyone to see (and steal) but generally you aren t doing amazingly sophisticated thingswith scripting languages so it s not too much of a hardship.This points out that scripting languages are really intended to solve specific types ofproblems, primarily the creation of richer and more interactive graphical user interfaces(GUIs).However, a scripting language might solve 80 percent of the problems encountered inclient-side programming.Your problems might very well fit completely within that 80percent, and since scripting languages tend to be easier and faster to develop, you shouldprobably consider a scripting language before looking at a more involved solution such asJava or ActiveX programming.The most commonly-discussed scripting languages are JavaScript (which has nothing to dowith Java; it s named that way just to grab some of Java s marketing momentum), VBScript(which looks like Visual Basic) and Tcl/Tk, which comes from the popular cross-platformGUI-building language.There are others out there and no doubt more in development.JavaScript is probably the most commonly supported.It comes built into both NetscapeNavigator and the Microsoft Internet Explorer (IE).In addition, there are probably moreJavaScript books out than for the other languages, and some tools automatically createpages using JavaScript.However, if you re already fluent in Visual Basic or Tcl/Tk, you ll bemore productive using those scripting languages rather than learning a new one.(You llhave your hands full dealing with the Web issues already.)60 Thinking in Java www.BruceEckel.com JavaIf a scripting language can solve 80 percent of the client-side programming problems, whatabout the other 20 percent  the  really hard stuff? The most popular solution today isJava.Not only is it a powerful programming language built to be secure, cross-platform andinternational, but Java is being continuously extended to provide language features andlibraries that elegantly handle problems that are difficult in traditional programminglanguages, such as multithreading, database access, network programming and distributedcomputing.Java allows client-side programming via the applet.An applet is a mini-program that will run only under a Web browser.The applet isdownloaded automatically as part of a Web page (just as, for example, a graphic isautomatically downloaded).When the applet is activated it executes a program.This is partof its beauty  it provides you with a way to automatically distribute the client softwarefrom the server at the time the user needs the client software, and no sooner.They get thelatest version of the client software without fail and without difficult re-installation.Becauseof the way Java is designed, the programmer needs to create only a single program, and thatprogram automatically works with all computers that have browsers with built-in Javainterpreters.(This safely includes the vast majority of machines.) Since Java is a full-fledgedprogramming language, you can do as much work as possible on the client before and aftermaking requests of the server.For example, you won t need to send a request form acrossthe Internet to discover that you ve gotten a date or some other parameter wrong, and yourclient computer can quickly do the work of plotting data instead of waiting for the server tomake a plot and ship a graphic image back to you.Not only do you get the immediate winof speed and responsiveness, but the general network traffic and load upon servers can bereduced, preventing the entire Internet from slowing down.One advantage a Java applet has over a scripted program is that it s in compiled form, so thesource code isn t available to the client.On the other hand, a Java applet can be decompiledwithout too much trouble, and hiding your code is often not an important issue anyway.Two other factors can be important.As you will see later in the book, a compiled Java appletcan comprise many modules and take multiple server  hits (accesses) to download.(In Java1.1 this is minimized by Java archives, called JAR files, that allow all the required modulesto be packaged together for a single download.) A scripted program will just be integratedinto 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 site.Another factor is the all-important learning curve.Regardless of what you ve heard, Java is not a trivial language tolearn.If you re a Visual Basic programmer, moving to VBScript will be your fastest solutionand since it will probably solve most typical client/server problems you might be hardpressed to justify learning Java [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • czarkowski.pev.pl
  •