10
CGI-
web- CGI-.
Web
C++Builder Web TWebModule. . TWebModule . , File | New | Other New Items New Web Server Application. , . CGI Stand-alone executable CGI. C++Builder .
C++ Builder 6 5. C++Builder 6 , , , .. , , : , . (Object TreeView), , (, , Actions ). .
C++ Builder 5 Web , . Data Diagram, . ++ Builder , .
Web ( ++ Builder 5 , WebModulel). Actions. TWebActi-onltem. , Actions. , ( C++Builder 5 WebModulel) Action Editor. Add New , Delete Selected ( ) , .
TWebActionltems , , . , . Pathlnfo. , URL. URL , , :
|
|
http://www.myserv.com/pi/servl.exe/actionl?value=5&Resp=Yes
URL (HTTP). ( www.myserv.com). ( /pl/servl.exe). , URL, Pathlnfo. /actionl. . , , . URL, Query . , , . "&". value 5 Resp Yes. , .
Pathlnfo. Pathlnfo URL. , Pathlnfo Pathlnfo. OnAction, , . :
void __fastcall TWebModulel::WebModulelWebActionItemlAction(
TObject *Sender, TWebRequest *Request, TWebResponse *Response, bool SHandled)
Request TWebRequest. Query string, Query URL. URL : value=5&Resp=Yes. QueryFields TStrings. Query URL . : value=5 Resp=Yes. , QueryFields . 1[]. , Request>Query-Fields>Values["Resp"] Yes.
Response TWebResponse. Content string HTML, HTML .
Handled , , Response . , Response , Handled false. , , Response, Content , .
Pathlnfo OnAction. Default. true, . , Pathlnfo , OnAction . Enabled .
|
|
TWebModule, , , . BeforeDispatch AfterDispatch, . OnAction. , BeforeDispatch. , , Enabled . . AfterDispatch. , , - .
, , . 1. , . , , : 4 5. , .
, , ( File | New | Other, Web Server Application). . .
Pathlnfo /1. . . Default true.
OnAction . :
void __fastcall TWebModulel::WebModulelWebActionItem2Action (
TObject *Sender, TWebRequest *Request, TWebResponse *Response, bool SHandled){
Response->Content = "<hl> ? </hl>" "<> 2x2?</p><HR>"
"< HREF=\"/cgi-bin/TwiceTwo.exe/l?4\"> 4</A> " "< HREF=\"/cgi-bin/TwiceTwo.exe/l?5\">5</A>?, <HR>"; Handled = true; }
HTML. 4 5. Pathlnfo /1. , , Pathlnfo. Query : 4 5. , . OnAction :
void __fastcall TWebModulel::WebModulelWebActionItemlAction(
TObject *Sender, TWebRequest *Request, TWebResponse *Response, bool SHandled) { if(Request->Query == "4")
Response->Content = " 4. !"; else Response->Content =
" 5. ."; Handled = true; }
Request.Query.
TwiceTwo. TwiccTwo.exe . .
. . , , HTML , . , , :
<html>
<head>
<title>3naeTe nBa</title>
|
|
</head>
<body>
<p> ?</p>
<> 2x2?</>
<hr>
<>< HREF="http://mycomputer/cgi-bin/TwoTwo.exe/l?4">4</a>
< HREF="http://mycomputer/cgi-bin/TwoTwo./1?5">5</>? </>
<hr>
</body>
</html>
, , , TwiceTwo.exe, : http://mycomputer/cgi-bin/ TwoTwo.exe. , HTML TwoTwo.exe, , . , TwiceTwo.exe.
TwoTwo.html. TwoTwo, . , . Pathlnfo = "\1"< . . TwoTwo nepeHecnfe . TwoTwo.html , , .
. HTML. .
<form name="form1" method="post" action="project2.exe">
<input type="text" name="textfield">
<input type="submit" name="Submit" value="">
</form>
:
http://server/my/project2.exe?textfield=%D2%E5%F1%F2&Submit=%C7%E0%EF%F0%EE%F1
, = . . , .
, post get. post. VCL.
-.
void __fastcall TWebModule1::WebModule1WebActionItem1Action(
TObject *Sender, TWebRequest *Request, TWebResponse *Response,
bool &Handled)
{
AnsiString A=Request->ContentFields->Values["textfield"];
AnsiString R="<html>\n<h1>Good day, dear "+A+"</h1>\n";
TDateTime D;
D=D.CurrentTime();
R+=D.TimeString() +"</html>";
Response->Content=R;
}
Request Pesponse. , Response->Content HTML.
, VCL:
Request->ContentFields->Values["textfield"]
- Response->Content. :
<html>
<h1>Good day, dear Guest</h1>
13:50:07</html>