开发者

How to create dynamic HTML pages using C? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 6 years ago.

Improve this question 开发者_运维百科

How to create DHTML pages using C language? Please give me some web site where I can find the step by step procedure to create DHTML pages using C.

Regards, NM


Assuming your application will be executed as a CGI of apache or another HTTP server, you only need to print the HTTP headers and the content of the page to stdout.

The minimal headers expected are:

Content-type: text/html\r\n\r\n

(do not forget the double \r\n)

then write your page.


C? Not so suitable language for that.

But, someone did CMS with that, called Tokyopromenade, Opensource

http://1978th.net/tokyopromenade/

Just for your information


For using C to generate (D|X)HTML, you will have to write CGI programs. CGI programs should output the Content-type: text/html or equivalent before HTML is output.

After that, you can upload the program to the cgi-bin/ or equivalent directory. Remember to set the execution bit on the file.


Have your C program write Content-type: text/html\n\n to stdout before anything else, and you can then generate whatever HTML you wish. The empty line is critical!


"DHTML" is mostly used to describe client-side functionality, and you use Javascript for that.

But if you mean dynamic web pages (server-side functionality), and you must use C, you can use CGI (Common Gateway Interface, RFC3875):

http://hoohoo.ncsa.illinois.edu/cgi/primer.html

However, using C for web pages is not a good choice. It would be better to use a scripting language like Python or Ruby, and either study the CGI support in that language or go for a framework like Ruby on Rails.


To create dynamic webpages using C, there are a couple of ways you can go about this (this is not an exhaustive list):

  1. You use CGI, an old standard for creating dynamic webpages. The way this works is that for each request to your site, your webserver creates a new process, invokes your program (passing information about the request to your program using environmental variables and stdin), and feeds the output from your program to the web browser. As other replies have noted, CGI requires your program to specify the HTTP response headers to the browser.

  2. If you're interesting in using C for performance reasons when developing webpages (this is sort of diving into insanity), CGI clearly isn't an option. If you're this much of a masochist, you should probably look into linking with FastCGI or creating an Apache module. In fact, since you like pain this much, you might as well just start with thttpd and insert your code where needed.

Good luck. You might also consider seeing a shrink.


Search "C library for web applications" here on stackoverflow, it has some good answers.

I haven't tried it, maybe someone would find it usefull: klone. It is a framework for building standalone web serververs and html templating with embedded C.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜