⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb200006ne_f.asp.htm

📁 C++builder学习资料C++builder
💻 HTM
📖 第 1 页 / 共 4 页
字号:
    

<p class=BodyText> It    

should be pointed out that <i>TWebModule</i>    

can simplify creating Web applications for processing user entries. A typical    

example of such an application is a form that must be filled in by a user. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> Let's    

modify our example by adding another <i>TWebActionItem</i>    

object (see Figure 9). </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Captions><img width=250    

 height=105 src="images/cb200006ne_f_image017.gif" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image017.gif"> <br>    

<b>Figure 9:</b>    

Adding another <i>TWebActionItem</i> object    

to show an HTML form. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

    

    

<p class=BodyText> Let this    

action be the default <i>TWebAction</i>.    

Then, place a <i>TPageProducer</i> component    

in our <i>WebModule1</i>. This component    

will generate an HTML document from a previously prepared template (see Figure    

10). </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Captions><img width=179    

 height=121 src="images/cb200006ne_f_image018.gif" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image018.gif"> <br>    

<b>Figure 10:</b>    

Adding <i>TPageProducer</i> to WebModule1. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

    

    

<p class=BodyText> To    

create this template, we must use an HTML editor that allows creating forms,    

e.g. Microsoft FrontPage (see Figure 11). </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Captions> <img    

 width=250 height=194 src="images/cb200006ne_f_image020.gif" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image020.gif"> <br>    

<b>Figure 11: </b>Creating    

an HTML form with Microsoft FrontPage. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

    

    

<p class=BodyText> The HTML    

source for the document in Figure 11 looks like the following: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code>&lt;html&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;head&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;meta    

http-equiv=&quot;Content-Type&quot; content=&quot;text/html; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;charset=windows-1251&quot;&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;meta    

name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 2.0&quot;&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;title&gt;Untitled    

Normal Page&lt;/title&gt;&lt;/head&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;body    

bgcolor=&quot;#FFFFFF&quot;&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;p&gt;&amp;nbsp;&lt;/p&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;form    

method=&quot;GET&quot;&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;p&gt;What    

is Your name?&lt;font size=&quot;4&quot;&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;input    

type=&quot;text&quot; size=&quot;20&quot;    

name=&quot;T1&quot;&gt;&lt;/font&gt;&lt;/p&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;p&gt;What    

is Your e-mail?&lt;font size=&quot;4&quot;&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;input    

type=&quot;text&quot; size=&quot;20&quot; name=&quot;T2&quot;&gt;&lt;/font&gt;&lt;/p&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;p&gt;&lt;font    

size=&quot;4&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;B1&quot; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;value=&quot;Submit&quot;&gt;&lt;input    

type=&quot;reset&quot; name=&quot;B2&quot; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;value=&quot;Reset&quot;&gt;&lt;/font&gt;&lt;/p&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;/form&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;/body&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;/html&gt; </span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> This    

document can be saved to a file, and in this case, we must type its name in the    

<i>HTMLFile</i> property of the <i    

style='mso-bidi-font-style:normal'>TPageProducer</i> component. We can also    

copy the HTML source to the Clipboard, and paste it into the <i    

style='mso-bidi-font-style:normal'>HTMLDoc</i> property editor. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> Now, we    

must create the <i>OnAction</i> event    

handler for the <i>TWebActionItem2</i>    

component: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>void</b> <b    

style='mso-bidi-font-weight:normal'>__fastcall</b> TWebModule1::WebModule1WebActionItem2Action(</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;TObject *Sender, TWebRequest *Request,    

TWebResponse *Response, </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b> bool</b>    

&amp;Handled) </span></p>    

    

<p class=Code><span class=Code>{</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;Response-&gt;Content=PageProducer1-&gt;Content();</span></p>    

    

<p class=Code><span class=Code>}</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> Compile    

and save this project. Then test it (see Figure 12). </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Captions> <img    

 width=250 height=166 src="images/cb200006ne_f_image022.gif" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image022.gif"><br>     

<b>Figure 12:</b>    

Testing the Web application with the created form. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

    

    

<p class=BodyText> Now we    

must process the user input, for example, by generating an HTML page with data    

from the edit fields of this form. So we must add another <i>TPageProducer</i> component (see Figure 13). </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Captions> <img    

 width=179 height=121 src="images/cb200006ne_f_image023.gif" tppabs="http://www.cbuilderzine.com/features/2000/06/cb200006ne_f/cb200006ne_f_image023.gif"><br>     

<b>Figure 13:</b>    

Adding <i>PageProducer2</i> to generate HTML pages by processing the results of    

the user entry. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

    

    

<p class=BodyText> Insert    

the following text into its <i>HTMLDoc</i>    

property: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code>&lt;html&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;head&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;title&gt;Thank    

You!&lt;/title&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;/head&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;body &gt; </span></p>    

    

<p class=Code><span class=Code>&lt;p&gt;Dear&nbsp;&nbsp;&lt;#T1&gt;!&lt;/p&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;p&gt;Thank    

you for completing this form. We have included your</span></p>    

    

<p class=Code><span class=Code>e-mail address    

&lt;#T2&gt; in our mailing list. You will receive a</span></p>    

    

<p class=Code><span class=Code>lot of spam    

from us!&lt;/p&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;/body&gt; </span></p>    

    

<p class=Code><span class=Code>&lt;/html&gt; </span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> This is    

a document template. It contains special tags that will be replaced by strings    

from the edit fields of the previous form. In the case of our application,    

these tags are &lt;#T1&gt; and &lt;#T2&gt;. They are the names of the edit    

fields of the input form (you can look at the form HTML source and find them    

there). </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> To    

replace these tags, we must create the <i>OnHTMLTag</i>    

event handler of the <i>PageProducer2</i>    

component: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>void</b> <b    

style='mso-bidi-font-weight:normal'>__fastcall</b>    

TWebModule1::PageProducer2HTMLTag(</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;TObject *Sender, TTag Tag, <b    

style='mso-bidi-font-weight:normal'>const</b> AnsiString TagString, </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;TStrings *TagParams,&nbsp;&nbsp; AnsiString &amp;ReplaceText) </span></p>    

    

<p class=Code><span class=Code>{</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;ReplaceText =    

Request-&gt;QueryFields-&gt;Values[TagString] +</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;Request-&gt;ContentFields-&gt;Values[TagString]; </span></p>    

    

<p class=Code><span class=Code>}</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> <i>Request</i>    

is the <i>TWebRequest</i> object generated    

by a user request. The <i>QueryFields</i>    

property - a <i>TStrings</i> object -    

contains the names of parameters and their values entered by a user, in the    

form Name=Value. They    

are stored in the QUERY_STRING environment variable of the Web server in the    

form of Name1=Value1&amp;Name2=Value2&amp;... <i>TagString</i>    

is a string contained in a tag to be replaced. The <i>Values </i>property of the <i>TStrings</i>    

object is used if strings contained in this object can be represented in the    

form Name=Value, as in    

this case. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> It    

should be mentioned that the &lt;form&gt; tag of the form's HTML source can use    

the GET method instead of the POST method. In this case, we must use the <i    

style='mso-bidi-font-style:normal'>ContentFields</i> property instead of the <i    

style='mso-bidi-font-style:normal'>QueryFields</i> property. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> Now    

create the next <i>TWebAction</i> with: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code>PathInfo="/t3" </span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> to    

represent a page generated by <i>PageProducer2</i>,    

and add its <i>OnAction</i> event handler: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>void</b> <b    

style='mso-bidi-font-weight:normal'>__fastcall</b>    

TWebModule1::WebModule1WebActionItem3Action(</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;TObject *Sender, TWebRequest *Request,    

TWebResponse *Response, </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b> bool</b>    

&amp;Handled) </span></p>    

    

<p class=Code><span class=Code>{</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;Response-&gt;Content=PageProducer2-&gt;Content();</span></p>    

    

<p class=Code><span class=Code>}</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> How can    

this page generation be initiated after the user presses the Submit button? We must take care of the processing of this event, which    

should be done by editing the <i>HTMLDoc</i>    

property of the <i>PageProducer1</i>    

component: </p>    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -