|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
无法实现跨操作系统的应用。当然这也是微软的理由之一,只有这样才能发挥ASP最佳的能力。可是我却认为正是Windows限制了ASP,ASP的概念本就是为一个能让系统运行于一个大的多样化环境而设计的;DreamweaverMX已正式公布了,Deamweaver4+DeamweaverULTRADEV4的组合使他成为固然的制做网页的首选工具,(好象做告白:) )
好了,进进正题,
我在之前做网页的分页时分都是用本人写的服务端剧本(我从不必ADO的分页),用了MX后发明在这内里用分页太便利了,不外代码也有点太长了,人人看上面的代码就能够晓得。用过以后我发明内里recordset的cursortype设为0分页居然能够一般事情!这令我受惊很多,剖析了代码以后才发明MX是用了一种挺笨的办法完成的,效力很低,以是人人仍是用1吧:)
剖析以下:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%>
<!--#includefile="Connections/ncarcnn.asp"-->
<%
DimRecordset1
DimRecordset1_numRows
SetRecordset1=Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection=MM_ncarcnn_STRING
Recordset1.Source="SELECT*FROMdbo.ncarinfo"
Recordset1.CursorType=0
这里用0也能够一般运转,可是经由剖析代码能够看出,用0的效力很低,倡议用1
Recordset1.CursorLocation=2
Recordset1.LockType=1
Recordset1.Open()
Recordset1_numRows=0
%>
<%
以下为分页代码
DimRepeat1__numRows
DimRepeat1__index
Repeat1__numRows=10
Repeat1__index=0
Recordset1_numRows=Recordset1_numRows+Repeat1__numRows
%>
<%
***Recordset形态,界说形态变量
DimRecordset1_total
DimRecordset1_first
DimRecordset1_last
settherecordcount
Recordset1_total=Recordset1.RecordCount
setthenumberofrowsdisplayedonthispage
If(Recordset1_numRows<0)Then
Recordset1_numRows=Recordset1_total
Elseif(Recordset1_numRows=0)Then
Recordset1_numRows=1
EndIf
setthefirstandlastdisplayedrecord
Recordset1_first=1
Recordset1_last=Recordset1_first+Recordset1_numRows-1
ifwehavethecorrectrecordcount,checktheotherstats处置准确的rs
If(Recordset1_total-1)Then
If(Recordset1_first>Recordset1_total)Then
Recordset1_first=Recordset1_total
EndIf
If(Recordset1_last>Recordset1_total)Then
Recordset1_last=Recordset1_total
EndIf
If(Recordset1_numRows>Recordset1_total)Then
Recordset1_numRows=Recordset1_total
EndIf
EndIf
%>
<%
***RecordsetStats:ifwedontknowtherecordcount,manuallycountthem处置毛病的RS
If(Recordset1_total=-1)Then
countthetotalrecordsbyiteratingthroughtherecordset
Recordset1_total=0
While(NotRecordset1.EOF)
Recordset1_total=Recordset1_total+1
Recordset1.MoveNext
Wend
resetthecursortothebeginning
If(Recordset1.CursorType>0)Then
Recordset1.MoveFirst
Else
Recordset1.Requery
EndIf
setthenumberofrowsdisplayedonthispage
If(Recordset1_numRows<0OrRecordset1_numRows>Recordset1_total)Then
Recordset1_numRows=Recordset1_total
EndIf
setthefirstandlastdisplayedrecord
Recordset1_first=1
Recordset1_last=Recordset1_first+Recordset1_numRows-1
If(Recordset1_first>Recordset1_total)Then
Recordset1_first=Recordset1_total
EndIf
If(Recordset1_last>Recordset1_total)Then
Recordset1_last=Recordset1_total
EndIf
EndIf
%>
<%
DimMM_paramName
%>
<%
***MoveToRecordandGoToRecord:declarevariables
DimMM_rs
DimMM_rsCount
DimMM_size
DimMM_uniqueCol
DimMM_offset
DimMM_atTotal
DimMM_paramIsDefined
DimMM_param
DimMM_index
SetMM_rs=Recordset1
MM_rsCount=Recordset1_total
MM_size=Recordset1_numRows
MM_uniqueCol=""
MM_paramName=""
MM_offset=0
MM_atTotal=false
MM_paramIsDefined=false
If(MM_paramName"")Then
MM_paramIsDefined=(Request.QueryString(MM_paramName)"")
EndIf
%>
<%
***MoveToRecord:handleindexoroffsetparameter
if(NotMM_paramIsDefinedAndMM_rsCount0)then
useindexparameterifdefined,otherwiseuseoffsetparameter
MM_param=Request.QueryString("index")
If(MM_param="")Then
MM_param=Request.QueryString("offset")
EndIf
If(MM_param"")Then
MM_offset=Int(MM_param)
EndIf
ifwehavearecordcount,checkifwearepasttheendoftherecordset
If(MM_rsCount-1)Then
If(MM_offset>=MM_rsCountOrMM_offset=-1)Thenpastendormovelast
If((MM_rsCountModMM_size)>0)Thenlastpagenotafullrepeatregion
MM_offset=MM_rsCount-(MM_rsCountModMM_size)
Else
MM_offset=MM_rsCount-MM_size
EndIf
EndIf
EndIf
movethecursortotheselectedrecord
MM_index=0
While((NotMM_rs.EOF)And(MM_index<MM_offsetOrMM_offset=-1))
MM_rs.MoveNext
MM_index=MM_index+1
Wend
If(MM_rs.EOF)Then
MM_offset=MM_indexsetMM_offsettothelastpossiblerecord
EndIf
EndIf
%>
<%
***MoveToRecord:ifwedontknowtherecordcount,checkthedisplayrange
If(MM_rsCount=-1)Then
walktotheendofthedisplayrangeforthispage
MM_index=MM_offset
While(NotMM_rs.EOFAnd(MM_size<0OrMM_index<MM_offset+MM_size))
MM_rs.MoveNext
MM_index=MM_index+1
Wend
ifwewalkedofftheendoftherecordset,setMM_rsCountandMM_size
If(MM_rs.EOF)Then
MM_rsCount=MM_index
If(MM_size<0OrMM_size>MM_rsCount)Then
MM_size=MM_rsCount
EndIf
EndIf
ifwewalkedofftheend,settheoffsetbasedonpagesize
If(MM_rs.EOFAndNotMM_paramIsDefined)Then
If(MM_offset>MM_rsCount-MM_sizeOrMM_offset=-1)Then
If((MM_rsCountModMM_size)>0)Then
MM_offset=MM_rsCount-(MM_rsCountModMM_size)
Else
MM_offset=MM_rsCount-MM_size
EndIf
EndIf
EndIf
resetthecursortothebeginning
If(MM_rs.CursorType>0)Then
MM_rs.MoveFirst
Else
MM_rs.Requery
EndIf
movethecursortotheselectedrecord
MM_index=0
While(NotMM_rs.EOFAndMM_index<MM_offset)
MM_rs.MoveNext
MM_index=MM_index+1
Wend
EndIf
%>
<%
***MoveToRecord:updaterecordsetstats
setthefirstandlastdisplayedrecord
Recordset1_first=MM_offset+1
Recordset1_last=MM_offset+MM_size
If(MM_rsCount-1)Then
If(Recordset1_first>MM_rsCount)Then
Recordset1_first=MM_rsCount
EndIf
If(Recordset1_last>MM_rsCount)Then
Recordset1_last=MM_rsCount
EndIf
EndIf
setthebooleanusedbyhideregiontocheckifweareonthelastrecord
MM_atTotal=(MM_rsCount-1AndMM_offset+MM_size>=MM_rsCount)
%>
<%
***GoToRecordandMoveToRecord:createstringsformaintainingURLandFormparameters
DimMM_keepNone
DimMM_keepURL
DimMM_keepForm
DimMM_keepBoth
DimMM_removeList
DimMM_item
DimMM_nextItem
createthelistofparameterswhichshouldnotbemaintained
MM_removeList="&index="
If(MM_paramName"")Then
MM_removeList=MM_removeList&"&"&MM_paramName&"="
EndIf
MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""
addtheURLparameterstotheMM_keepURLstring
ForEachMM_itemInRequest.QueryString
MM_nextItem="&"&MM_item&"="
If(InStr(1,MM_removeList,MM_nextItem,1)=0)Then
MM_keepURL=MM_keepURL&MM_nextItem&Server.URLencode(Request.QueryString(MM_item))
EndIf
Next
addtheFormvariablestotheMM_keepFormstring
ForEachMM_itemInRequest.Form
MM_nextItem="&"&MM_item&"="
If(InStr(1,MM_removeList,MM_nextItem,1)=0)Then
MM_keepForm=MM_keepForm&MM_nextItem&Server.URLencode(Request.Form(MM_item))
EndIf
Next
createtheForm+URLstringandremovetheintial&fromeachofthestrings
MM_keepBoth=MM_keepURL&MM_keepForm
If(MM_keepBoth"")Then
MM_keepBoth=Right(MM_keepBoth,Len(MM_keepBoth)-1)
EndIf
If(MM_keepURL"")Then
MM_keepURL=Right(MM_keepURL,Len(MM_keepURL)-1)
EndIf
If(MM_keepForm"")Then
MM_keepForm=Right(MM_keepForm,Len(MM_keepForm)-1)
EndIf
autilityfunctionusedforaddingadditionalparameterstothesestrings
FunctionMM_joinChar(firstItem)
If(firstItem"")Then
MM_joinChar="&"
Else
MM_joinChar=""
EndIf
EndFunction
%>
<%
***MoveToRecord:setthestringsforthefirst,last,next,andpreviouslinks
DimMM_keepMove
DimMM_moveParam
DimMM_moveFirst
DimMM_moveLast
DimMM_moveNext
DimMM_movePrev
DimMM_urlStr
DimMM_paramList
DimMM_paramIndex
DimMM_nextParam
MM_keepMove=MM_keepBoth
MM_moveParam="index"
ifthepagehasarepeatedregion,removeoffsetfromthemaintainedparameters
If(MM_size>1)Then
MM_moveParam="offset"
If(MM_keepMove"")Then
MM_paramList=Split(MM_keepMove,"&")
MM_keepMove=""
ForMM_paramIndex=0ToUBound(MM_paramList)
MM_nextParam=Left(MM_paramList(MM_paramIndex),InStr(MM_paramList(MM_paramIndex),"=")-1)
If(StrComp(MM_nextParam,MM_moveParam,1)0)Then
MM_keepMove=MM_keepMove&"&"&MM_paramList(MM_paramIndex)
EndIf
Next
If(MM_keepMove"")Then
MM_keepMove=Right(MM_keepMove,Len(MM_keepMove)-1)
EndIf
EndIf
EndIf
setthestringsforthemovetolinks
If(MM_keepMove"")Then
MM_keepMove=MM_keepMove&"&"
EndIf
MM_urlStr=Request.ServerVariables("URL")&"?"&MM_keepMove&MM_moveParam&"="
MM_moveFirst=MM_urlStr&"0"
MM_moveLast=MM_urlStr&"-1"
MM_moveNext=MM_urlStr&CStr(MM_offset+MM_size)
If(MM_offset-MM_size<0)Then
MM_movePrev=MM_urlStr&"0"
Else
MM_movePrev=MM_urlStr&CStr(MM_offset-MM_size)
EndIf
%>
<html>
<head>
<title>UntitledDocument</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>
<body>
<p></p>
<tableborder="1">
<tr>
<td>cpno</td>
<td>cbno</td>
<td>cdpt</td>
<td>cid</td>
<td>cbnm</td>
<td>ddate</td>
<td>cstate</td>
<td>guid</td>
</tr>
<%While((Repeat1__numRows0)AND(NOTRecordset1.EOF))%>
<tr>
<td><%=(Recordset1.Fields.Item("cpno").Value)%></td>
<td><%=(Recordset1.Fields.Item("cbno").Value)%></td>
<td><%=(Recordset1.Fields.Item("cdpt").Value)%></td>
<td><%=(Recordset1.Fields.Item("cid").Value)%></td>
<td><%=(Recordset1.Fields.Item("cbnm").Value)%></td>
<td><%=(Recordset1.Fields.Item("ddate").Value)%></td>
<td><%=(Recordset1.Fields.Item("cstate").Value)%></td>
<td><%=(Recordset1.Fields.Item("guid").Value)%></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table>
<p></p>
<tableborder="0"width="50%"align="center">
<tr>
<tdwidth="23%"align="center"><%IfMM_offset0Then%>
<ahref="<%=MM_moveFirst%>"><%IfNotMM_atTotalThen%>
<ahref="<%=MM_moveNext%>"></a>
<%EndIfendNotMM_atTotal%></td>
</tr>
</table>
Records<%=(Recordset1_first)%>to<%=(Recordset1_last)%>of<%=(Recordset1_total)%>
</body>
</html>
<%
Recordset1.Close()
SetRecordset1=Nothing
%>
编译成dll用也能够:)
ASP由于使用了COM组件所以它会变的十分强大,但是这样的强大由于WindowsNT系统最初的设计问题而会引发大量的安全问题。只要在这样的组件或是操作中一不注意,哪么外部攻击就可以取得相当高的权限而导致网站瘫痪或者数据丢失; |
|