How To Dynamic Web Rendering?

Nick Sabalausky a at a.a
Thu May 12 13:01:02 PDT 2011


"Matthew Ong" <ongbp at yahoo.com> wrote in message 
news:iqgo17$2nqv$1 at digitalmars.com...
> Hi Adam,
>
> Thanks again for the sharp pointed answer.
>> What is the counterpart in D for replacing JSP/ASP/JRuby on Rail or
>> some sort of dynamic web base development?
>
>>I use D for web work by using the standard CGI interface and >sometimes
>>an embedded http server. It's the best thing I've ever used.
> Could you share how or show an URL that provide sample code to do that in 
> D?
>
>
>> How to also code digitally sign the DLL  that was compiled in D?
> The same way you sign any other dll/exe.
> So we use external tool to do that and not a build in one??
> In java, we use jarsigner with some keygen.
>
> Please bear in mind I am new to D.
>

Here's a basic "Hello world" CGI app in D:

// hellocgi.d
import std.conv;
import std.stdio;

void main()
{
    // Read in HTTP request headers
    string[] requestHeaders;
    while(true)
    {
        string line = readln();
        if(line.length <= 1)
            break;

        requestHeaders ~= line;
    }

    // Send response headers
    writeln("Status: 200 OK");
    writeln("Content-Type: text/html; charset=UTF-8");
    writeln();

    // Send content
    writeln("<b><i>Hello world</i></b>");
}

Compile with:
dmd hellocgi.d

And just stick the resulting "hellocgi.exe" (windows) or "hellocgi" (other) 
in whatever "cgi-bin"-capable directory you have on your server.

Everything else (such as fancy CGI libraries/frameworks like Adam's) can 
ultimately be built out of that basic idea.

Keep in mind though, that since D is natively compiled, you'll have to 
compile it on either the same OS and CPU architecture as your server, or an 
OS/CPU that's compatible with your server. (This would be true of C/C++ as 
well.)

I'm sure it's possible to make an ISAPI filter or Apache module in D, but 
I've never really done that in any langauge, and I haven't really dealt with 
DLLs much, so I wouldn't know how. But even as CGI, a web app in D is likely 
to still be much faster than one in, for instance, PHP or Ruby.




More information about the Digitalmars-d-learn mailing list