|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
问题是他们究竟是喜欢他们是使用软件时,速度快还是速度慢好.(当然在3秒以内).无论是他们输入资料时,查找资料时,分析资料时.后面我们已先容了利用ASP和XML夹杂编程,那是由于ASP页面可以很简单让我们看清使用程序正在做甚么,可是你假如你不想利用ASP的话,你也能够利用任何你熟习的手艺往创立一个客户端程序。上面,我供应了一段VB代码,它的功效和ASP页面一样,也能够显现不异的数据,可是这个VB程序不会创立发送到服务器的XML字符串。它经由过程运转一个名叫Initialize的存储历程,从服务器取回XML字符串,来查询ClientCommands表的内容。
<P> ClientCommands表包含两个域:command_name域和command_xml域。客户端程序必要三个特定的command_name域:getCustomerList,CustOrderHist和RecentPurchaseByCustomerID。每个命令的command_xml域包含程序发送到getData.asp页面的XML字符串,如许,就能够会合把持XML字符串了,就象存储历程名字所体现的意义一样,在发送XML字符串到getData.asp之前,客户端程序利用XMLDOM来设置存储历程的参数值。我供应的代码,包括了用于界说Initialize历程和用于创立ClientCommands表的SQL语句。
我供应的例程中还申明了怎样利用XHTTPRequest工具完成我在本文一入手下手时许下的答应:任何远程的呆板上的使用程序都能够会见getData.asp;固然,你也能够经由过程设置IIS和NTFS权限来限定会见ASP页面;你能够在服务器上而不是客户机上存储全局使用程序设置;你能够制止经由过程收集发送数据库用户名和暗码所带来的隐患性。另有,在IE中,使用程序能够只显现必要的数据而不必革新全部页面。
在实践的编程过程当中,你们应该利用一些办法使使用程序加倍有高效性。你能够把ASP中的关于获得数据的代码端搬到一个COM使用程序中往然后创立一个XSLT变更来显现前往的数据。好,我未几说了,如今你所要做的就是试一试吧!
<P> OptionExplicit
PrivateRCommandsAsRecordset
PrivateRCustomersAsRecordset
PrivateRCustAsRecordset
PrivatesCustListCommandAsString
PrivateConstdataURL=http://localhost/XHTTPRequest/getData.asp
PrivatearrCustomerIDs()AsString
PrivateEnumActionEnum
VIEW_HISTORY=0
VIEW_RECENT_PRODUCT=1
EndEnum
PrivateSubdgCustomers_Click()
DimCustomerIDAsString
CustomerID=RCustomers(CustomerID).Value
IfCustomerID<>Then
IfoptAction(VIEW_HISTORY).ValueThen
CallgetCustomerDetail(CustomerID)
Else
CallgetRecentProduct(CustomerID)
EndIf
EndIf
EndSub
PrivateSubForm_Load()
Callinitialize
CallgetCustomerList
EndSub
Subinitialize()
从数据库前往命令名和响应的值
DimsXMLAsString
DimvRetAsVariant
DimFAsField
sXML=<?xmlversion=1.0?>
sXML=sXML&<command><commandtext>Initialize</commandtext>
sXML=sXML&<returnsdata>True</returnsdata>
sXML=sXML&</command>
SetRCommands=getRecordset(sXML)
DoWhileNotRCommands.EOF
ForEachFInRCommands.Fields
Debug.PrintF.Name&=&F.Value
Next
RCommands.MoveNext
Loop
EndSub
FunctiongetCommandXML(command_nameAsString)AsString
RCommands.MoveFirst
RCommands.Findcommand_name=&command_name&,,adSearchForward,1
IfRCommands.EOFThen
MsgBoxCannotfindanycommandassociatedwiththename&command_name&.
ExitFunction
Else
getCommandXML=RCommands(command_xml)
EndIf
EndFunction
SubgetRecentProduct(CustomerIDAsString)
DimsXMLAsString
DimxmlAsDOMDocument
DimNAsIXMLDOMNode
DimproductNameAsString
sXML=getCommandXML(RecentPurchaseByCustomerID)
Setxml=NewDOMDocument
xml.loadXMLsXML
SetN=xml.selectSingleNode(command/param[name=CustomerID]/value)
N.Text=CustomerID
Setxml=executeSPWithReturn(xml.xml)
productName=xml.selectSingleNode(values/ProductName).Text
显现text域
txtResult.Text=
Me.txtResult.Visible=True
dgResult.Visible=False
显现product名
txtResult.Text=比来的产物是:&productName
EndSub
SubgetCustomerList()
DimsXMLAsString
DimiAsInteger
DimsAsString
sXML=getCommandXML(getCustomerList)
SetRCustomers=getRecordset(sXML)
SetdgCustomers.DataSource=RCustomers
EndSub
SubgetCustomerDetail(CustomerIDAsString)
找出列表中相干联的ID号
DimsXMLAsString
DimRAsRecordset
DimFAsField
DimsAsString
DimNAsIXMLDOMNode
DimxmlAsDOMDocument
sXML=getCommandXML(CustOrderHist)
Setxml=NewDOMDocument
xml.loadXMLsXML
SetN=xml.selectSingleNode(command/param[name=CustomerID]/value)
N.Text=CustomerID
SetR=getRecordset(xml.xml)
埋没text,由于它是一个纪录集
txtResult.Visible=False
dgResult.Visible=True
SetdgResult.DataSource=R
EndSub
FunctiongetRecordset(sXMLAsString)AsRecordset
DimRAsRecordset
DimxmlAsDOMDocument
Setxml=getData(sXML)
Debug.PrintTypeName(xml)
OnErrorResumeNext
SetR=NewRecordset
R.Openxml
IfErr.Number<>0Then
MsgBoxErr.Description
ExitFunction
Else
SetgetRecordset=R
EndIf
EndFunction
FunctionexecuteSPWithReturn(sXMLAsString)AsDOMDocument
DimdAsNewDictionary
DimxmlAsDOMDocument
DimnodesAsIXMLDOMNodeList
DimNAsIXMLDOMNode
Setxml=getData(sXML)
Ifxml.documentElement.nodeName=valuesThen
SetexecuteSPWithReturn=xml
Else
产生毛病
SetN=xml.selectSingleNode(response/data)
IfNotNIsNothingThen
MsgBoxN.Text
ExitFunction
Else
MsgBoxxml.xml
ExitFunction
EndIf
EndIf
EndFunction
FunctiongetData(sXMLAsString)AsDOMDocument
DimxhttpAsNewXMLHTTP30
xhttp.OpenPOST,dataURL,False
xhttp.sendsXML
Debug.Printxhttp.responseText
SetgetData=xhttp.responseXML
EndFunction
PrivateSuboptAction_Click(IndexAsInteger)
CalldgCustomers_Click
EndSub
代码2、getData.asp
<P> <%@Language=VBScript%>
<%optionexplicit%>
<%
SubresponseError(sDescription)
Response.Write<response><data>Error:&sDescription&</data></response>
Response.end
EndSub
Response.ContentType=text/xml
dimxml
dimcommandText
dimreturnsData
dimreturnsValues
dimrecordsAffected
dimparam
dimparamName
dimparamType
dimparamDirection
dimparamSize
dimparamValue
dimN
dimnodeName
dimnodes
dimconn
dimsXML
dimR
dimcm
创立DOMDocument工具
Setxml=Server.CreateObject(msxml2.DOMDocument)
xml.async=False
装载POST数据
xml.LoadRequest
Ifxml.parseError.errorCode<>0Then
CallresponseError(不克不及装载XML信息。形貌:&xml.parseError.reason&<br>行数:&xml.parseError.Line)
EndIf
客户端必需发送一个commandText元素
SetN=xml.selectSingleNode(command/commandtext)
IfNIsNothingThen
CallresponseError(Missing<commandText>parameter.)
Else
commandText=N.Text
EndIf
客户端必需发送一个returnsdata大概returnsvalue元素
setN=xml.selectSingleNode(command/returnsdata)
ifNisnothingthen
setN=xml.selectSingleNode(command/returnsvalues)
ifNisnothingthen
callresponseError(Missing<returnsdata>or<returnsValues>parameter.)
else
returnsValues=(lcase(N.Text)=true)
endif
else
returnsData=(lcase(N.Text)=true)
endif
setcm=server.CreateObject(ADODB.Command)
cm.CommandText=commandText
ifinstr(1,commandText,,vbBinaryCompare)>0then
cm.CommandType=adCmdText
else
cm.CommandType=adCmdStoredProc
endif
创立参数
setnodes=xml.selectNodes(command/param)
ifnodesisnothingthen
假如没有参数
elseifnodes.length=0then
假如没有参数
else
foreachparaminnodes
Response.Writeserver.HTMLEncode(param.xml)&<br>
onerrorresumenext
paramName=param.selectSingleNode(name).text
iferr.number<>0then
callresponseError(创立参数:不克不及发明称号标签。)
endif
paramType=param.selectSingleNode(type).text
paramDirection=param.selectSingleNode(direction).text
paramSize=param.selectSingleNode(size).text
paramValue=param.selectSingleNode(value).text
iferr.number<>0then
callresponseError(参数名为¶mName&的参数短少需要的域)
endif
cm.Parameters.Append cm.CreateParameter(paramName,paramType,paramDirection,paramSize,paramValue)
iferr.number<>0then
callresponseError(不克不及创立或增加名为¶mName&的参数.& err.description)
Response.end
endif
next
onerrorgoto0
endif
翻开保持
setconn=Server.CreateObject(ADODB.Connection)
conn.Mode=adModeReadWrite
conn.openApplication(ConnectionString)
iferr.number<>0then
callresponseError(保持堕落:&Err.Description)
Response.end
endif
保持Command工具
setcm.ActiveConnection=conn
实行命令
ifreturnsDatathen
用命令翻开一个Recordset
setR=server.CreateObject(ADODB.Recordset)
R.CursorLocation=adUseClient
R.Opencm,,adOpenStatic,adLockReadOnly
else
cm.ExecuterecordsAffected,,adExecuteNoRecords
endif
iferr.number<>0then
callresponseError(实行命令毛病&Commandtext&:&Err.Description)
Response.end
endif
ifreturnsDatathen
R.SaveResponse,adPersistXML
iferr.number<>0then
callresponseError(数据集产生存储毛病,在命令&CommandText&:&Err.Description)
Response.end
endif
elseifreturnsValuesthen
sXML=<?xmlversion=1.0encoding=gb2312?>&vbcrlf&<values>
setnodes=xml.selectNodes(command/param[direction=2])
foreachNinnodes
nodeName=N.selectSingleNode(name).text
sXML=sXML&<&nodename&>&cm.Parameters(nodename).Value&&</&nodename&>
next
sXML=sXML&</values>
Response.WritesXML
endif
setcm=nothing
conn.Close
setR=nothing
setconn=nothing
Response.end
%>
楼上说交互性不好,太牵强了吧。在微软提供的一套框架中,利用asp做网站,开发效率高,使用人数少,减少不必要的开销。交互性是互动方式,是有开发人员决定的。 |
|