C++ Web Programming
2015-08-19 14:22
525 查看
CGI的说明书是由NCSA维护,NCSA定义CGI的范畴:一般的网关接口或者CGI是外部网关程序的一个标准,它与信息server交互。当前的CGI版本号是CGI/3.2.9,兴许版本号还在开发中。
一般的网关程序(CGI)是一个标准协议,它可以使应用程序(称之为CGI程序或者CGI脚本)与Webserver和client进行交互。
这些CGI程序可以使用Python、PERL、Shell,C或者C++等编写。
以下介绍一个实例,依据这个实例来说明,怎样使用CGI。
首先,必须配置HTTPserver,这里。我们选择ApacheHttpd作为HTTP协议的server。CGI设置例如以下:
#change the directoryRootvariable in httpd.conf file DocumentRoot"/usr/local/apache-2.4.9/htdocs" #set theaccess control <Directory"/usr/local/apache-2.4.9"> … #enable the cgi module LoadModule cgid_module modules/mod_cgid.so #set the directoryproperties <Directory "/usr/local/apache-2.4.9/cgi-bin"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> <Directory "/usr/local/apache-2.4.9/cgi-bin"> Options All </Directory>
编写一个C++的CGI程序,并编译它得到cpp.cgi文件。改变这个文件的全部权限,使用命令“chmod 755 cpp.cgi”。
cpp.cpp文件
#include <iostream> using namespace std; int main () { cout << "Content-type:text/html\r\n\r\n"; cout << "<html>\n"; cout << "<head>\n"; cout << "<title>C++ CGI Welcome you</title>\n"; cout << "</head>\n"; cout << "<body>\n"; cout << "<h2>Congratulation, you enter into the world of CGI.</h2>\n"; cout << "</body>\n"; cout << "</html>\n"; return 0; }
将编译后的cgi文件放置指定的路径(/usr/local/apache-2.4.9/cgi-bin)下。启动httpd服务。浏览页面:
http://hadoop-master/cgi-bin/cpp.cgi
相关文章推荐
- c++ primer plus 第九章《编程题9.6.2》
- c++ primer plus 第十章-编程题6
- C语言数组和指针的区别
- 【C语言】typedef
- 第五章 数组与C++标准库类模板vector
- (转载)C++ using namespace std 用法深入解析
- C++编程所遇到的error(持续更新和补充)
- 关于c语言和c++的区别和联系
- C++之动态绑定和静态绑定
- C++缓冲区的知识
- 时间转换<将秒转换为天、小时、分钟>
- 任意输入三个数判断其是否为三角形
- C++构造函数的调用
- 保存FLTK的配置方法
- [C++]Ugly Number 丑数
- acm c++常用函数(stl)
- Windows下C++访问数据库(ADO)
- C++封装C#的类库DLL,并c++中C#的string类型的转换使用
- C++ ARGB 和 16进制相互转换
- 如何优化C/C++语言代码(程序员必读)