如何使用C ++ CGI脚本? [英] How To Use C++ CGI Script?

查看:157
本文介绍了如何使用C ++ CGI脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的大学注册了一个web应用程序课程,我们正在学习cgi脚本。我很难学习如何实现我的CGI脚本。当我点击我的链接时,会弹出一个窗口,要求我下载我的helloworld.cgi文件而不是重定向。

HTML:
$ b

 < HTML> 
< body>
< a href =/ user / local / apache2 / cgi-bin / helloworld.cgi>点击我< / a>
< / body>
< / html>

C ++:

  #include< iostream> 

使用namespace std;

int main(){
cout<< Content-type:text / html<< ENDL;
cout<< < HTML> 中<< ENDL;
cout<< < body> << ENDL;
cout<< 你好,世界! << ENDL;
cout<< < / body> << ENDL;
cout<< < / HTML> 中<< ENDL;

返回0;

CGI脚本存储在 / user / local /apache2/cgi-bin/helloworld.cgi

解决方案

/ user /local/apache2/cgi-bin/helloworld.cgi 是硬盘上文件的物理路径。要通过Apache运行脚本,您需要指定相对于服务器文档根目录的路径,例如。 http://localhost/cgi-bin/helloworld.cgi


I am currently enrolled in a web applications class at my college and we are learning about cgi scripts. I am having a hard time learning how to implement my CGI script. When I click on my link a window pops up asking me to download my helloworld.cgi file instead of just redirecting.

HTML:

<html>
    <body>
        <a href="/user/local/apache2/cgi-bin/helloworld.cgi">click me</a>
    </body>
</html>

C++:

#include <iostream>

using namespace std;

int main(){
    cout << "Content-type: text/html" << endl;
    cout << "<html>" << endl;
    cout << "   <body>" << endl;
    cout << "       Hello World!" << endl;
    cout << "   </body>" << endl;
    cout << "</html>" << endl;

    return 0;
    }

The CGI script is stored at /user/local/apache2/cgi-bin/helloworld.cgi

解决方案

/user/local/apache2/cgi-bin/helloworld.cgi is the physical path of the file on your hard disk. To run the script through Apache, you need to specify the path relative to your server's document root, for eg. http://localhost/cgi-bin/helloworld.cgi.

这篇关于如何使用C ++ CGI脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆