Common Gateway Interface
- 博客分类:
- java
A web server that supports CGI can be configured to interpret(解析) a URL that it serves as a reference to CGI scripts. A common convention is to have a cgi-bin/ directory at the base of the directory tree and treat all executable files within it as CGI scripts. Another popular convention is to use filename extensions; for instance, if CGI scripts are consistently given the extension .cgi, the web server can be configured to interpret all such files as CGI scripts.
In the case of HTTP PUT or POSTs, the user-submitted data is provided to the program via the standard input. In any case, according to the CGI standard, data is passed into the program using certain, specific environment variables. This is in contrast to typical execution, where command-line arguments are used and the environment is in constant upheaval and cannot be trusted. Apache creates a small, efficient subset of the environment variables passed to it and adds details pertinent to the execution of the program.
[edit]Simple Example
The following CGI program shows all the environment variables passed by the web server:
#!/usr/local/bin/perl ## ## printenv—demo CGI program which just prints its environment ## # print "Content-type: text/plain\n\n"; foreach $var (sort(keys(%ENV))) { $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print "${var}=\"${val}\"\n"; }
- If a web browser request the document at http://example.com/cgi-bin/printenv.pl/ponylove?q=20%C001er&moar=kitties, the following information is returned:
COMSPEC="C:\Windows\system32\cmd.exe" DOCUMENT_ROOT="C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs" GATEWAY_INTERFACE="CGI/1.1" HOME="/home/SYSTEM" HTTP_ACCEPT="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" HTTP_ACCEPT_CHARSET="ISO-8859-1,utf-8;q=0.7,*;q=0.7" HTTP_ACCEPT_ENCODING="gzip, deflate" HTTP_ACCEPT_LANGUAGE="en-us,en;q=0.5" HTTP_CONNECTION="keep-alive" HTTP_COOKIE="ShowBlockedFriends=1; oneswarmView=list; swarmsPerPage=6; Community contacts=true; OneSwarm=Y6XAAAAAX; friend_list_open=true" HTTP_HOST="example.com" HTTP_USER_AGENT="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0" PATH="/home/SYSTEM/bin:/bin:/cygdrive/c/progra~2/php:/cygdrive/c/windows/system32:..." PATHEXT=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" PATH_INFO="/ponylove" PATH_TRANSLATED="C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\ponylove" QUERY_STRING="q=20%C001er&moar=kitties" REMOTE_ADDR="127.0.0.1" REMOTE_PORT="63555" REQUEST_METHOD="GET" REQUEST_URI="/cgi-bin/printenv.pl/ponylove?q=20%C001er&moar=kitties" SCRIPT_FILENAME="C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/printenv.pl" SCRIPT_NAME="/cgi-bin/printenv.pl" SERVER_ADDR="127.0.0.1" SERVER_ADMIN="(server admin's email address)" SERVER_NAME="127.0.0.1" SERVER_PORT="80" SERVER_PROTOCOL="HTTP/1.1" SERVER_SIGNATURE="" SERVER_SOFTWARE="Apache/2.2.19 (Win32) PHP/5.2.17" SYSTEMROOT="C:\Windows" TERM="cygwin" WINDIR="C:\Windows"
From the environment, we see that the web browser is Firefox running on Windows 7 running on a PC, the web server is an Apache running on a system which emulates Unix, and the CGI script is named cgi-bin/printenv.pl.
The program could then generate any content, that written to its standard output, will be transmitted by the web server to the browser.
[edit]Environment variables passed to a CGI program
-
Server specific variables:
- SERVER_SOFTWARE — name/version of HTTP server.
- SERVER_NAME — host name of the server, may be dot-decimal IP address.
- GATEWAY_INTERFACE — CGI/version.
-
Request specific variables:
- SERVER_PROTOCOL — HTTP/version.
- SERVER_PORT — TCP port (decimal).
- REQUEST_METHOD — name of HTTP method (see above).
- PATH_INFO — path suffix, if appended to URL after program name and a slash.
- PATH_TRANSLATED — corresponding full path as supposed by server, if PATH_INFO is present.
- SCRIPT_NAME — relative path to the program, like /cgi-bin/script.cgi.
- QUERY_STRING — the part of URL after ? character. May be composed of *name=value pairs separated with ampersands (such as var1=val1&var2=val2…) when used to submit form data transferred via GET method as defined by HTML application/x-www-form-urlencoded.
- REMOTE_HOST — host name of the client, unset if server did not perform such lookup.
- REMOTE_ADDR — IP address of the client (dot-decimal).
- AUTH_TYPE — identification type, if applicable.
- REMOTE_USER used for certain AUTH_TYPEs.
- REMOTE_IDENT — see ident, only if server performed such lookup.
- CONTENT_TYPE — MIME type of input data if PUT or POST method are used, as provided via HTTP header.
- CONTENT_LENGTH — similarly, size of input data (decimal, in octets) if provided via HTTP header.
- Variables passed by user agent (HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE, HTTP_USER_AGENT, HTTP_COOKIE and possibly others) contain values of corresponding HTTP headers and therefore have the same sense.
[edit]Output format
The program returns the result to the web server in the form of standard output, prefixed by a header and a blank line.
The header is encoded in the same way as an HTTP header and must include the MIME type of the document returned.[1] The headers are generally forwarded with the response back to the user, supplemented by the web server.
[edit]Example
An example of a CGI program is one implementing a wiki. The user agent requests the name of an entry; the server retrieves the source of that entry's page (if one exists), transforms it into HTML, and sends the result.
发表评论
-
Classloader
2011-11-22 14:09 715The class loader: BootStrap c ... -
JUnit Knowledges
2011-10-25 23:09 705mock objects: http://bigwhite. ... -
Java跨平台程序设计规则
2011-09-20 12:38 921不是说所有的Java程序都具有Java跨平台的特性,事实上,相 ... -
Servlet - life cycle and listener events
2011-08-25 15:56 786import database.BookDBAO; ... -
什么时候使用属性或者元素(Designing XML document)
2011-08-19 11:34 976Properties 是平面结构,想要表达结构复杂的信息有一定 ... -
Java - Generic
2011-07-19 12:35 684Generics <!--[if !suppor ... -
Java Exception Study
2011-07-13 16:37 812Java Exception <!--[if ! ... -
面向对象的设计的四个主要原则
2011-07-11 14:22 13081. ISP (Interface Segregation ... -
Design Pattern
2011-07-11 11:52 619Mediator 一、引子 中介在现实 生活中并 ... -
Java Generic, Association, Composition, Aggregate
2011-07-05 16:20 1121UML中依赖泛化关联实现聚合组合的Java实现 ... -
ETL
2011-06-30 11:36 823ETL 对于数据仓库以及ETL的知识,我基本上是个 ... -
Java Collection Frameworks 学习
2011-06-30 11:17 659Java 集合总结 <!--[if !su ... -
Java Clone
2011-06-29 16:07 772Clone interface: 如果一个实现了Cl ... -
Credit Card 的工具类
2010-05-10 15:24 842这是一个非常有用的工具类用于验证credit card, 是a ... -
实例化抽象类时实现抽象类里的抽象方法
2010-04-16 09:18 975EccTrxCmd logWSCall = new EccTr ... -
Java reflect
2010-03-09 16:21 784【转】Java反射经典实例 Java Reflection C ...
相关推荐
CGI 意思为 Common Gateway Interface, 一种基于浏览器的输入、在Web服务器上运行的程序方法. CGI脚本 使你的浏览器与用户能交互,为了在数据库中 寻找一个名词, 提供你写入的评论,或者从一个表单中选择几个条目...
有需要的没有积分的,可以发邮件h5ru@qq.com,我发给你。 The Common Gateway Interface (CGI) Version 1.1,CGI规范
CGI(Common Gateway Interface: 公用网关接口)规定了Web服务器调用其他可执行程序(CGI 程序)的接口协议标准。Web服务器通过调用CGI程序实现和Web浏览器的交互,也就是CGI程序接受Web浏览器发送给Web服务器的信息,进行...
action属性指明当前表单提交之后由哪个程序来处理,这个处理程序可以是任何动态网页或者servlet或者CGI(Common Gateway Interface),在asp.net里面一般都是都aspx页面来处理。 method属性指明form表单的提交方式。...
Initially, Common Gateway Interface (CGI) scripts were the main technology used to generate dynamic content. Although widely used, CGI scripting technology has a number of shortcomings, including ...
公共网关接口CGI(Common Gateway Interface) CGI是较早实现的技术。适用于多种服务器平台,如UNIX、WINDOWS等,但CGI的开发成本高、维护困难、功能有限、不具备事务处理功能、占用服务器资源较多。 2. INTERNET...
JavaWeb面试题说出Servlet的生命周期,并说出Servlet和CGI[CGI(Common Gateway Interface,公用网关接口)是较早用来建立动态网页的技术。当客户端向Web服务器上指定的CGI程序发出请求时,Web服务器会启动一个新的...
(1)cgi(common gateway interface) 特点: a:cgi技术是早期动态技术使用最多,发展比较成熟并且功能强大 b:效率比较低,编程比较困难 c:cgi可以用不同的语言编写(vb,delphi,c/c++,perl)常用的c/c++和...
ASP技术 ASP(Active Server Pages动态网页)是微软公司推出的一种用以取代CGI(Common Gateway Interface通用网关接口)的技术。目前,Internet上的许多基于Windows平台的Web站点已开始应用ASP来替换CGI。 简单地讲...
Java Servlet 通常情况下与使用 CGI(Common Gateway Interface,公共网关接口)实现的程序可以达到异曲同工的效果。 ———————————————— 版权声明:本文为CSDN博主「那山的狐狸」的原创文章,遵循CC ...
ASP(Active Server Pages)动态网页,是微软公司推出的一种用以取代CGI(Common Gateway Interface)通用网关接口的技术。我们可以通过ASP结合HTML语言、ASP指令和ActiveX组件以及数据库等方面知识,使用自己的 Web ...
此“CGI”并非指“公共网关接口”(Common Gateway Interface),也与相关的技术无关。此处的CGI(Console Graphic Interface),即“控制台图形界面”,是自定义的一套控制台应用程序“图形化”界面开发解决方案。...
ment retrieval protocol was subverted by the Common Gateway Interface into serving up dynamically-generated documents delivering data from a database back-end, allowing online access to one’s data ...
CGI(Common Gateway Interface)公共网关接口,是外部扩展应用程序与 Web 服务器交互的一个标准接口。服务器端与客户端进行交互的常见方式多,CGI 技术就是其中之一。根据CGI标准,编写外部扩展应用程序,可以对...
ASP(Active Server Page)是微软公司推出的一种用以取代通用网关接口(Common Gateway Interface)的技术。从字面上说,ASP包含三方面含义:(1) Active:ASP使用了Microsoft的ActiveX技术。ActiveX是Microsoft...
PHP运行模式有4钟:1)cgi 通用网关接口(Common Gateway Interface))2) fast-cgi 常驻 (long-live) 型的 CGI3) cli 命令行运行 (Command Line Interface)4)web模块模式 (apache等web服务器运行的模块模式...
这些通常是使用公共网关接口(CGI(Common Gateway Interface))应用程序完成的。然而,在服务器上运行Java,这种程序可使用Java编程语言实现。在通信量大的服务器上,Javaservlet的优点在于它们的执行速度更快于CGI...
在Internet飞速发展的今天,...ASP技术ASP(Active Server Pages动态网页)是微软公司推出的一种用以取代CGI(Common Gateway Interface通用网关接口)的技术。目前,Internet上的许多基于Windows平台的Web站点已开始
CGI(Common Gateway Interface,通用网关界面)是一种Web服务器上运行的基于Web浏览器输入程序的方法,是最早的访问数据库的解决方案。CGI程序可以建立网页与数据库之间的连接,将用户的查询要求转换成数据库的查询...
Introduction to the Common Gateway Interface (CGI). 7. Object-Based Programming: Classes and Data Abstraction. 8. Object-Oriented Programming: Inheritance and Polymorphism. 9. Operator Overloading...