⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch1.htm

📁 CGI programming is the hottest stuff to look out for in this book
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<HTML>

<HEAD>
   <TITLE>Chapter 1 -- What CGI Programs Can and Can't
Do</TITLE>
   <META>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">
<H1><FONT COLOR=#FF0000>Chapter 1</FONT></H1>
<H1><B><FONT SIZE=5 COLOR=#FF0000>What CGI Programs Can and Can't
Do</FONT></B>
</H1>
<P>
<HR WIDTH="100%"></P>
<P>
<H3 ALIGN=CENTER><FONT COLOR="#000000"><FONT SIZE=+2>CONTENTS<A NAME="CONTENTS"></A>
</FONT></FONT></H3>

<UL>
<LI><A HREF="#WhatCGIIsUsefulFor" >What CGI Is Useful For</A>
<UL>
<LI><A HREF="#SimpleTasks" >Simple Tasks</A>
<LI><A HREF="#IntermediateTasks" >Intermediate Tasks</A>
<LI><A HREF="#AdvancedTasks" >Advanced Tasks</A>
</UL>
<LI><A HREF="#WhatCGIIsNotUsefulFor" >What CGI Is Not Useful For</A>
<LI><A HREF="#WhatCGIProgramsCanDo" >What CGI Programs Can Do</A>
<UL>
<LI><A HREF="#WhatCGICantDo" >What CGI Can't Do</A>
</UL>
<LI><A HREF="#Summary" >Summary</A>
</UL>
<HR>
<P>
The first things you should know about Common Gateway Interface
(CGI) are what it is and why it is used. CGI is a standard whose
specification defines a way for Web servers to communicate with
external programs, and vice versa, so that the external program
can generate HTML, images, or whatever, and have the server treat
it the same as HTML, images, and so on not generated by an external
program. The reason CGI is used is so you can generate dynamic
content with the same ease that you generate static content. CGI
is used because it is a very well defined and supported standard,
and without CGI, dynamic content would have been impossible without
proprietary server methods (now, there are alternatives to CGI
that are becoming standard).
<P>
There are many useful applications of CGI programs. But, as with
every other technology, CGI programs have their limits. Also,
as with many other technologies, it is not always the best way
to do things. For this reason, this chapter will go over what
CGI programs can and cannot do, and what CGI based apps are good
and bad for.
<P>
For comparison's sake, I use Java as the applet language.
<H2><A NAME="WhatCGIIsUsefulFor"><FONT SIZE=5 COLOR=#FF0000>What
CGI Is Useful For</FONT></A></H2>
<P>
As stated earlier, CGI is useful for many different tasks. There
are different reasons why it is the best method, or the only method,
for a variety of tasks. This chapter examines the reasons, separating
the tasks into three different levels. First, we cover simple
tasks, which we will define as tasks that can be completed in
a couple of hours and/or require almost no knowledge of how to
program CGI apps/the CGI spec in general. This task level includes
counters, among other things. Next, we cover intermediate tasks,
which we will define as tasks that can be completed in a day or
two and/or tasks that require a pretty good knowledge of how to
program CGI apps/the CGI spec in general. This task level includes
built from scratch imagemapping programs, apps that generate entire
HTML pages, and apps that do animation, among other things. Finally,
we cover advanced tasks, which we will define as tasks that take
more than a day or two and/or require an expertise in CGI app
programming/the CGI spec in general. This task level includes
apps that include a home grown database engine, among other things.
<H3><A NAME="SimpleTasks">Simple Tasks</A></H3>
<P>
The following is a list of simple tasks in CGI, most of which
are covered in this section:
<UL>
<LI><FONT COLOR=#000000>Hit Counters (text based)</FONT>
<LI><FONT COLOR=#000000>Programs that generate HTML for simple
things like the current date, and so on</FONT>
<LI><FONT COLOR=#000000>Any Perl CGI program that is less than
about 50 lines</FONT>
<LI><FONT COLOR=#000000>Any C CGI program that is less than 50
lines</FONT>
<LI><FONT COLOR=#000000>Any C++ CGI program that is less than
50 lines</FONT>
</UL>
<P>
The first level of CGI tasks we will examine are simple tasks.
These are tasks that take almost no programming to perform. An
example of a simple task would be a <I>hit counter</I>. These
are CGI scripts written in either Perl, C, or maybe just a simple
shell script, but they all basically work the same way (assuming
it's not a very advanced counter). They keep a single data file
that stores the number of hits. The program reads that data file
and when called, increments the number by one and then returns
that number. The code to a counter can be found at <TT><FONT FACE="Courier"><A HREF="ftp://server.berkeley.edu/pub/www/counter">ftp://server.berkeley.edu/pub/www/counter</A></FONT></TT>,
and many other places on the Web. CGI is obviously not the only
method for creating counters, but as things stand today, it is
the best, for three main reasons.
<P>
The first reason that CGI is the best method is simply because
it is currently the quickest. The overhead of doing a counter
in Java is currently immense because the language is interpreted.
Given that there is no advantage to using Java, there is no point.
<P>
The second reason is because the CGI standard is the most compatible
with today's browsers. Java is not supported by a lot of browsers
yet, and the ones that do support it don't do so on all platforms.
CGI is a technology that interfaces with HTML. CGI apps generate
HTML, or images. Java is a technology that allows you to write
real programs and put them on a Web page (assuming you are just
writing applets).
<P>
The third reason is availability. In my Web travels, when searching
for CGI developer resources, I have seen tons of CGI-based counters
and CGI code to perform simple tasks, but next to nothing in the
way of code for Java. Eventually, this will change due to resources
like Gamelan (the official Java applet/application repository,
located at <TT><FONT FACE="Courier"><A HREF="http://www.gamelan.com">http://www.gamelan.com</A></FONT></TT>),
but since this has not happened yet, it is always easier to use
code already written than it is to write your own. This (the prewritten
code) is a major factor as to why simple tasks are done in CGI:
They are already done by someone else, usually include ample documentation
and commented source code, and are waiting for you to just implement
on your server.
<P>
As we climb up the ladder of difficulty, we reach intermediate
CGI tasks, such as the creation of image maps and animation, which
are covered in the next section.
<H3><A NAME="IntermediateTasks">Intermediate Tasks</A></H3>
<P>
The second level of tasks we will examine are intermediate level
tasks. This would include things like imagemapping and various
other programming tasks that require significant programming work
to perform. As you get into intermediate tasks, the line starts
to blur on what is easier to do in CGI and what is easier to do
in Java.
<P>
Some of the tasks that fit into this category are
<UL>
<LI><FONT COLOR=#000000>Imagemaps</FONT>
<LI><FONT COLOR=#000000>CGI scripts that generate entire pages
of HTML</FONT>
<LI><FONT COLOR=#000000>Animation</FONT>
</UL>
<P>
While basic imagemapping requires no programming when done on
the client side, doing something more than just jumping to an
HTML page when you click on an image requires programming.
<P>
As an example to determine CGI's usefulness for these tasks and
its efficiency, we will use a CGI program that handles image zooming.
When I click on the image, it zooms in.
<P>
There are two ways to do this. You could use CGI and some other
program to zoom in, and return a zoomed-in image (written either
by yourself or taken from somewhere else), or you could do it
in Java, dynamically resizing the image, on the same Web page.
So which is better? Well, this is an example of an application
where the benefits of programming the application using a CGI
library versus programming in Java must be weighed. So let's do
that right now, but on a more general scale.
<P>
Pros of coding intermediate applications using CGI:
<UL>
<LI><FONT COLOR=#000000>Currently faster than interpreted Java</FONT>
</UL>
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
Just-In-Time compilers for Java, which speed up apps significantly, are becoming available, so the overhead that comes from the Java code being interpreted will eventually become a nonfactor.</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<UL>
<LI><FONT COLOR=#000000>Supported by all servers and clients</FONT>
<LI><FONT COLOR=#000000>Can use familiar programming language</FONT>
<LI><FONT COLOR=#000000>Less initial programming work</FONT>
<LI><FONT COLOR=#000000>You can differentiate between text clients
and graphical clients</FONT>
</UL>
<P>
Cons of coding intermediate applications using CGI:
<UL>
<LI><FONT COLOR=#000000>You hit the limitations of what you can
do rather quickly</FONT>
<LI><FONT COLOR=#000000>CGI uses up a lot of processing time,
while Java harnesses the power of the </FONT>client
</UL>
<P>
Pros of coding intermediate applications in Java:
<UL>
<LI><FONT COLOR=#000000>Is C-like, so if you know C, Java is fairly
easy to pick up</FONT>
<LI><FONT COLOR=#000000>Completely reusable and object-oriented</FONT>
<LI><FONT COLOR=#000000>Java consists of real, live applications
embedded into the Web page and is therefore fully interactive.</FONT>
<LI><FONT COLOR=#000000>Java APIs and the language itself are
growing up fast and are being embraced just as quickly</FONT>
</UL>
<P>
Cons of coding intermediate applications in Java:
<UL>
<LI><FONT COLOR=#000000>Not yet a full standard. Support on all
platforms not yet available from anyone</FONT>
<LI><FONT COLOR=#000000>Performance hit (see previous note)</FONT>
<LI><FONT COLOR=#000000>Currently requires more up front work
(this will change as more free reusable code becomes available)</FONT>
</UL>
<P>
Now that you know the pros and cons of coding the application
using either Java or a CGI library, which way should you choose?
Well, I can't answer that for you. As stated earlier, it varies
depending on what kind of application you're talking about, what
its purpose is, what the goals are, and so on. On the good side,
you do have more than one option for how to do something. Choices
are always good to have. They are also good to make, assuming
you make the right ones. As we climb to the next rung on the difficulty
ladder, we reach advanced-level tasks.
<H3><A NAME="AdvancedTasks">Advanced Tasks</A></H3>
<P>
Strangely, unlike intermediate tasks, the advanced tasks are currently
a lot easier to perform in CGI than in Java. Examples of such
tasks include
<UL>
<LI><FONT COLOR=#000000>Database Backending</FONT>
<LI><FONT COLOR=#000000>Search Engines</FONT>
<LI><FONT COLOR=#000000>Multiple Dynamic Pages</FONT>
</UL>
<P>
The third level of tasks we will examine are advanced tasks. Applications
that perform <I>database backending</I> (having an application
that accesses a database) are good examples of this.
<P>
This is true for a couple of reasons. First, as you have heard
many times before, CGI has been around longer and therefore is

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -