200分!紧急求助!关于TWebBrowser和IE的问题! ( 积分: 200 )

L

lvqher

Unregistered / Unconfirmed
GUEST, unregistred user!
我正在做一个基于ActiveX控件的项目,就是IE里面嵌入一个ActiveX,在ActiveX里面准备提交WEBSERVER一些重要的客户资料,我希望这些资料,比如用户,密码,手机号等,不出这个ActiveX,直接在ActiveX里面提交,我设计了这样的架构,用ActiveX提供一个Submit方法供HTML页面的JAVASCRIPT函数去调用,然后用这个方法去使用TWebBrowser去提交到WebServer,然后等ActiveX通过TWebBrowser收到WEBSERVER应答数据后,整个html显示新的数据,就等于是产生了一个新页面,这里的新页面要求不是在ActiveX中产生,而是在IE中产生,这时候原来的页面内容(HTML+ACTIVEX)不存在了。我的HTML代码和ActiveX的submit方法的代码我附在后面,现在的问题是我想WEBSERVER POST数据OK,也收到了回应,我如何才能把这些数据在IE上表现出来,我的IE如何才能像跳转到了其他页面那样产生一个新的应答页面。
HTML文本:
<html>
<head>
<title>用户登陆</title>
<meta http-equiv=&quot;Content-Type&quot
content=&quot;text/html;&quot;>
<LINK href=&quot;../theme/Master.css&quot
rel=&quot;stylesheet&quot
type=&quot;text/css&quot;>
<script language=&quot;JavaScript&quot
src=&quot;../script/date.js&quot;></script>
<script language=&quot;JavaScript&quot;>
</script>
<script language=&quot;JavaScript&quot;>
function validate_form()
{
validity = true
// assume valid
alert(document.form.safeEdit1.passwdtext);
document.form.userinfo.submit(document.form.loginid.value);
document.form.userinfo.reset();
return false;
}
</script>
</head>

<body >
<FORM name=&quot;form&quot
method=post onSubmit=&quot;return validate_form()&quot;>
<table border=&quot;0&quot
cellpadding=&quot;0&quot
cellspacing=&quot;0&quot
width=&quot;486&quot
align=&quot;center&quot;>
<tr>
<td rowspan=&quot;2&quot;&quot;>
<table width=&quot;85%&quot
border=&quot;0&quot
cellspacing=&quot;2&quot
cellpadding=&quot;2&quot
align=&quot;center&quot;>
<tr>
<td>
<div align=&quot;center&quot;>
<table width=230 height=&quot;100&quot
border=0 cellspacing=1>
<tbody>
<tr>
<td nowrap>用 户 号:</td>
<td nowrap>
<input size=&quot;19&quot
maxlength=19 name=loginid minlength=&quot;8&quot;>
</td>
</tr>
<tr>
<td nowrap>登录密码:</td>
<td nowrap>
<OBJECT
id=&quot;userinfo&quot;
classid=&quot;clsid:56F64A87-4EC1-438C-BD8C-34F114B8FEA1&quot;
codebase=&quot;userinfo.inf&quot;
width=200
height=160
align=center
hspace=0
vspace=0
>
</OBJECT>
</br>
</td>
</tr>
<tr align=middle>
<td nowrap colspan=2 height=43>
<div align=&quot;center&quot;>
<input type=submit height=26 width=61 name=submit>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td>&amp;nbsp;</td>
</tr>
<tr>
<td><font color=&quot;#FF0000&quot;>注意:</font></td>
</tr>
<tr>
<td>&amp;nbsp;</td>
</tr>
</table>
</td>
<td><img src=&quot;../images/spacer.gif&quot
width=&quot;1&quot
height=&quot;4&quot
border=&quot;0&quot;></td>
</tr>
<tr>
<td><img src=&quot;../images/spacer.gif&quot
width=&quot;1&quot
height=&quot;285&quot
border=&quot;0&quot;></td>
</tr>
</table>
</form>
</html>

SUBMIT方法:
Memo1.Lines.Add('DEbug start');
WebBrowser := TWebBrowser.Create(Self);

Self.ActiveFormControl.ClientSite.GetContainer(spIE);
if not Assigned(spIE) then Exit;
spIE.QueryInterface(IID_IHTMLDocument2,spDoc);
if not Assigned(spDoc) then Exit;
LocalUrl:= Trim(spDoc.url);

Memo1.Lines.Add(LocalUrl);
Memo1.Lines.Add(Globalstr);
EncodedDataString := 'loginid=' + HTTPEncode(LoginId) + '&amp;' + 'password=' + HttpEncode(Globalstr);
PostData := VarArrayCreate([0, Length(EncodedDataString) - 1], varByte);
for I := 1 to Length(EncodedDataString) do
PostData[I-1] := Ord(EncodedDataString);
Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;
ConfigName := filepath+'/'+'config.ini';
Memo1.Lines.Add(ConfigName);
JspIni := TIniFile.Create(ConfigName);
jspIndex:= JspIni.ReadString('Jsp','JspIndex','validateFinish.jsp');
JspIni.Free;
Memo1.Lines.Add(jspIndex);
JspUrl := GetNewUrl(LocalUrl,jspIndex);
Memo1.Lines.Add(JspUrl);
JspUrl := 'http://127.0.0.1:9000/sd/validateFinish.jsp';
WebBrowser.Navigate(JspUrl, EmptyParam,EmptyParam, PostData, Headers);

{
while WebBrowser.Busy do
Application.ProcessMessages;
}
repeat
Application.ProcessMessages ;
until(not WebBrowser.Busy);


if WebBrowser.document <> nil then
begin
doc := WebBrowser.document as Ihtmldocument2;
all := doc.all;
item:=all.item(0,varEmpty);
Memo1.Lines.Add(item.innerhtml );
end;

MEMO是一个调试工具,目前meno里确实能取到webserver返回的数据,我该怎么样把这个数据填充到页面上呢?(不是放到TWebBrowser容器里)
 
我正在做一个基于ActiveX控件的项目,就是IE里面嵌入一个ActiveX,在ActiveX里面准备提交WEBSERVER一些重要的客户资料,我希望这些资料,比如用户,密码,手机号等,不出这个ActiveX,直接在ActiveX里面提交,我设计了这样的架构,用ActiveX提供一个Submit方法供HTML页面的JAVASCRIPT函数去调用,然后用这个方法去使用TWebBrowser去提交到WebServer,然后等ActiveX通过TWebBrowser收到WEBSERVER应答数据后,整个html显示新的数据,就等于是产生了一个新页面,这里的新页面要求不是在ActiveX中产生,而是在IE中产生,这时候原来的页面内容(HTML+ACTIVEX)不存在了。我的HTML代码和ActiveX的submit方法的代码我附在后面,现在的问题是我想WEBSERVER POST数据OK,也收到了回应,我如何才能把这些数据在IE上表现出来,我的IE如何才能像跳转到了其他页面那样产生一个新的应答页面。
HTML文本:
<html>
<head>
<title>用户登陆</title>
<meta http-equiv=&quot;Content-Type&quot
content=&quot;text/html;&quot;>
<LINK href=&quot;../theme/Master.css&quot
rel=&quot;stylesheet&quot
type=&quot;text/css&quot;>
<script language=&quot;JavaScript&quot
src=&quot;../script/date.js&quot;></script>
<script language=&quot;JavaScript&quot;>
</script>
<script language=&quot;JavaScript&quot;>
function validate_form()
{
validity = true
// assume valid
alert(document.form.safeEdit1.passwdtext);
document.form.userinfo.submit(document.form.loginid.value);
document.form.userinfo.reset();
return false;
}
</script>
</head>

<body >
<FORM name=&quot;form&quot
method=post onSubmit=&quot;return validate_form()&quot;>
<table border=&quot;0&quot
cellpadding=&quot;0&quot
cellspacing=&quot;0&quot
width=&quot;486&quot
align=&quot;center&quot;>
<tr>
<td rowspan=&quot;2&quot;&quot;>
<table width=&quot;85%&quot
border=&quot;0&quot
cellspacing=&quot;2&quot
cellpadding=&quot;2&quot
align=&quot;center&quot;>
<tr>
<td>
<div align=&quot;center&quot;>
<table width=230 height=&quot;100&quot
border=0 cellspacing=1>
<tbody>
<tr>
<td nowrap>用 户 号:</td>
<td nowrap>
<input size=&quot;19&quot
maxlength=19 name=loginid minlength=&quot;8&quot;>
</td>
</tr>
<tr>
<td nowrap>登录密码:</td>
<td nowrap>
<OBJECT
id=&quot;userinfo&quot;
classid=&quot;clsid:56F64A87-4EC1-438C-BD8C-34F114B8FEA1&quot;
codebase=&quot;userinfo.inf&quot;
width=200
height=160
align=center
hspace=0
vspace=0
>
</OBJECT>
</br>
</td>
</tr>
<tr align=middle>
<td nowrap colspan=2 height=43>
<div align=&quot;center&quot;>
<input type=submit height=26 width=61 name=submit>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td>&amp;nbsp;</td>
</tr>
<tr>
<td><font color=&quot;#FF0000&quot;>注意:</font></td>
</tr>
<tr>
<td>&amp;nbsp;</td>
</tr>
</table>
</td>
<td><img src=&quot;../images/spacer.gif&quot
width=&quot;1&quot
height=&quot;4&quot
border=&quot;0&quot;></td>
</tr>
<tr>
<td><img src=&quot;../images/spacer.gif&quot
width=&quot;1&quot
height=&quot;285&quot
border=&quot;0&quot;></td>
</tr>
</table>
</form>
</html>

SUBMIT方法:
Memo1.Lines.Add('DEbug start');
WebBrowser := TWebBrowser.Create(Self);

Self.ActiveFormControl.ClientSite.GetContainer(spIE);
if not Assigned(spIE) then Exit;
spIE.QueryInterface(IID_IHTMLDocument2,spDoc);
if not Assigned(spDoc) then Exit;
LocalUrl:= Trim(spDoc.url);

Memo1.Lines.Add(LocalUrl);
Memo1.Lines.Add(Globalstr);
EncodedDataString := 'loginid=' + HTTPEncode(LoginId) + '&amp;' + 'password=' + HttpEncode(Globalstr);
PostData := VarArrayCreate([0, Length(EncodedDataString) - 1], varByte);
for I := 1 to Length(EncodedDataString) do
PostData[I-1] := Ord(EncodedDataString);
Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;
ConfigName := filepath+'/'+'config.ini';
Memo1.Lines.Add(ConfigName);
JspIni := TIniFile.Create(ConfigName);
jspIndex:= JspIni.ReadString('Jsp','JspIndex','validateFinish.jsp');
JspIni.Free;
Memo1.Lines.Add(jspIndex);
JspUrl := GetNewUrl(LocalUrl,jspIndex);
Memo1.Lines.Add(JspUrl);
JspUrl := 'http://127.0.0.1:9000/sd/validateFinish.jsp';
WebBrowser.Navigate(JspUrl, EmptyParam,EmptyParam, PostData, Headers);

{
while WebBrowser.Busy do
Application.ProcessMessages;
}
repeat
Application.ProcessMessages ;
until(not WebBrowser.Busy);


if WebBrowser.document <> nil then
begin
doc := WebBrowser.document as Ihtmldocument2;
all := doc.all;
item:=all.item(0,varEmpty);
Memo1.Lines.Add(item.innerhtml );
end;

MEMO是一个调试工具,目前meno里确实能取到webserver返回的数据,我该怎么样把这个数据填充到页面上呢?(不是放到TWebBrowser容器里)
 
将数据存到HTML文件中,然后再打开它。
 
那可能那样简单的就能解决问题!呵呵!
不过我最后还是用COM解决了这个问题!就是把IE作为一个对象通过IWEBBROWSER2接口在控件中使用,具体代码如下:
SP := self.ActiveFormControl.ClientSite as IServiceProvider;
SP.QueryService(IWebbrowserApp, IWebbrowser2, WebBrowser);
WebBrowser.Navigate(JspUrl, EmptyParam,EmptyParam, PostData, Headers);

虽然只有这关键的三行代码,却解决了我一星期都在思考的问题,几个不眠之夜呀!不过收获也挺大的,我感觉到了COM的强大威力,它确确实实的把一个公共的组件应用于了各个接口,感觉WINDOWS的架构设计确实太好了,在WINDOWS的开发中就为对象的复用,引用,调用提供了解决方案!要想成为WINDOWS开发高手,COM和接口这两方面一定要过关!
 
顶部