VFPCGI Day9
出自VFP Wiki
VFPCGI的第九天
有了 Request class,我們把 cgi05 改寫成 cgi06,不用自己再處理,改由 request class 去處理。
少掉前面的一堆處理,看起來是比較好一點了~ 下次來改寫 Request 來讓她可以處理中文。
* * cgi06 * SET PROCEDURE TO cgilib TRY LOCAL oResponse, oRequest oResponse = CREATEOBJECT( "RESPONSE" ) oRequest = CREATEOBJECT( "REQUEST" ) * 取得目前的 Request Method LOCAL cInput cInput = "<p>REQUEST_METHOD=" + oRequest.RequestMethod + "</p>" * 因為要去處理的 collection 不一樣 DO CASE CASE oRequest.RequestMethod == "POST" oCollection = oRequest.FormField OTHERWISE oCollection = oRequest.QueryString ENDCASE cInput = cInput + "<p><ul>" FOR i=1 TO oCollection.Count cInput = cInput + "<li>" + oCollection.GetKey(i) + "=" + oCollection.Item(i) + "</li>" ENDFOR cInput = cInput + "</ul></p>" * 輸出成 HTML 囉~ lcHtml = "" TEXT TO lcHtml NOSHOW ADDITIVE TEXTMERGE <script language="javascript"> function method_change( form ) { switch ( form.cboMethod.value ) { case "GET": form.method = "GET"; break; case "POST": form.method = "POST"; break; } } </script> <form method="get" action="vfpcgi.exe"> RequestMethod: <select name="cboMethod" onChange="return method_change(this.form);"> <option value="GET" <<IIF(oRequest.RequestMethod=="GET", "selected", "")>> >GET</option> <option value="POST" <<IIF(oRequest.RequestMethod=="POST", "selected", "")>> >POST</option> </select><br/> <input type="text" name="txt" value=""/> <select name="cbo"> <option value="0" selected>0</option> <option value="1">1</option> <option value="2">2</option> </select><br/> <input type="submit" value="Submit"/> <input type="reset" value="Reset"/> </form> <<cInput>> ENDTEXT oResponse.Write( lcHtml ) CATCH TO oError oResponse.Write( oError.Message ) FINALLY ENDTRY