zoukankan      html  css  js  c++  java
  • C++ Web Programming


             一般的网关接口或者CGI,就是一个标准的集合。它定义信息怎样再问吧server和一般脚本间的交换。

    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
    
    ";
       cout << "<html>
    ";
       cout << "<head>
    ";
       cout << "<title>C++ CGI Welcome you</title>
    ";
       cout << "</head>
    ";
       cout << "<body>
    ";
       cout << "<h2>Congratulation, you enter into the world of CGI.</h2>
    ";
       cout << "</body>
    ";
       cout << "</html>
    ";
       
       return 0;
    }
    


          将编译后的cgi文件放置指定的路径(/usr/local/apache-2.4.9/cgi-bin)下。启动httpd服务。浏览页面:

    http://hadoop-master/cgi-bin/cpp.cgi



    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    Python编码规范12-访问控制--访问控制
    Python编码规范11-命名规范--命名约定
    Python编码规范10-命名规范--命名规范
    Python编码规范09-注释--文档注释
    Python编码规范08-注释--代码注释
    Python编码规范07-基础规范--文件和sockets
    Python编码规范06-基础规范--字符串
    Python编码规范05-基础规范--文档字符串(docstring)
    Python编码规范04-基础规范--空格
    Python编码规范03-基础规范--import语句
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4742107.html
Copyright © 2011-2022 走看看