📄 tij0028.html
字号:
bandwidth would be exhausted for the kinds of applications people developed.
For example, any sort of dynamic 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 you’ve no doubt had direct
experience with something 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 sends the page back to you; you must then back
up a page and try again. Not only is this slow, it’s not elegant.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">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 next 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.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">The
problem with discussions of client-side programming is that they aren’t
very different from discussions 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, it’s still programming 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 programming.
</FONT><P></DIV>
<A NAME="Heading44"></A><H4 ALIGN=LEFT>
Plug-ins</H4>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">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 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 isn’t something
you’d 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
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>without
the permission of the browser manufacturer
</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">.
Thus, plug-ins provide the back door that allows the creation of new
client-side programming languages (although not all languages are implemented
as plug-ins).
</FONT><P></DIV>
<A NAME="Heading45"></A><H4 ALIGN=LEFT>
Scripting
languages
</H4>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">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 language is automatically activated while
the HTML page is being displayed. Scripting languages tend to be reasonably
simple 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 is that your code is exposed for everyone to
see (and steal) but generally you aren’t doing amazingly sophisticated
things with scripting languages so it’s not too much of a hardship.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">This
points out that scripting languages 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 might very
well fit completely within that 80 percent, and since scripting languages tend
to be easier and faster to develop, you should probably consider a scripting
language before looking at a more involved solution such as Java or ActiveX
programming.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">The
most commonly-discussed scripting languages are JavaScript (which has nothing
to do with 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-platform GUI-building language. There are others
out there and no doubt more in development.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">JavaScript
is probably the most commonly supported. It comes built into both Netscape
Navigator and the Microsoft Internet Explorer (IE). In addition, there are
probably more JavaScript books out than for the other languages, and some tools
automatically create pages using JavaScript. However, if you’re already
fluent in Visual Basic or Tcl/Tk, you’ll be more productive using those
scripting languages rather than learning a new one. (You’ll have your
hands full dealing with the Web issues already.)
</FONT><P></DIV>
<A NAME="Heading46"></A><H4 ALIGN=LEFT>
Java</H4>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">If
a scripting language can solve 80 percent of the client-side programming
problems, what about the other 20 percent – the “really 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 continuously extended to provide language
features and libraries that elegantly handle problems that are difficult in
traditional programming languages, such as multithreading, database access,
network programming and distributed computing. Java allows client-side
programming via the
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>applet</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">.</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">An
applet is a mini-program that will run only under a Web browser. The applet is
downloaded automatically as part of a Web page (just as, for example, a graphic
is automatically downloaded). When the applet is activated it executes a
program. This is part of its beauty – it 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. They get the latest version of
the client software without fail and without difficult re-installation. 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 interpreters. (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 won’t need to send a request form across
the Internet to discover that you’ve gotten 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 load upon servers can be reduced,
preventing the entire Internet from slowing down.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">One
advantage a Java applet has over a scripted program is that it’s in
compiled form, so the source code isn’t available to the client. On the
other hand, a Java applet can be decompiled without 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 applet can
comprise many modules and take multiple server “hits” (accesses) to
download. (In Java 1.1<A NAME="Index50"></A>
this is minimized by Java archives, called JAR files, that allow all the
required modules to be packaged together 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 site. Another factor is the all-important learning
curve. Regardless of what you’ve heard, Java is not a trivial language to
learn. If you’re 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 pressed to justify learning Java. If
you’re 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 you’ll be more productive sooner.
</FONT><P></DIV>
<A NAME="Heading47"></A><H4 ALIGN=LEFT>
ActiveX</H4>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">To
some degree, the competitor to Java is Microsoft’s ActiveX, although it
takes a completely different approach. ActiveX is 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 environment 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, you’re already an experienced
Windows programmer using a language such as C++, Visual Basic, or
Borland’s 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.
</FONT><P></DIV>
<A NAME="Heading48"></A><H4 ALIGN=LEFT>
Security</H4>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Automatically
downloading and running programs across the Internet can sound like a
virus-builder’s dream. ActiveX especially brings up the thorny issue of
security in client-side programming. If you click on a Web site, you might
automatically download any number of things along with the HTML page: GIF
files, script code, compiled Java code, and ActiveX components. Some of these
are benign; GIF files can’t do any harm, and scripting languages are
generally limited in what they can do. Java was also designed to run its
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -