基于asp网站设计的代码.docx
- 文档编号:17108244
- 上传时间:2023-07-22
- 格式:DOCX
- 页数:20
- 大小:19.43KB
基于asp网站设计的代码.docx
《基于asp网站设计的代码.docx》由会员分享,可在线阅读,更多相关《基于asp网站设计的代码.docx(20页珍藏版)》请在冰点文库上搜索。
基于asp网站设计的代码
附录
(1)数据库连接
使用ODBC驱动程序对数据库创建连接,其代码如下:
<%DimMM_xxnew_STRING
MM_xxnew_STRING="Driver={MicrosoftAccessDriver(*.mdb)};DBQ="&server.mappath("db/xxnews.mdb")
%>
(2)登录检验代码:
管理员登录后建立session变量
Session("admin")=username
权限的合法验证
<%
FunctioncheckPermission()
IfSession("admin")<>""then
checkPermission=TRUE
Else
checkPermission=FALSE
Endif
EndFunction
tmpadmin=checkPermission()
Iftmpadmin<>TRUEthen
response.redirect"login.asp?
"/如果不能通过验证,转到页面longin.asp
Endif
%>
(3)创建记录集代码:
<%
DimRecordset1
DimRecordset1_numRows
SetRecordset1=Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection=MM_xxnew_STRING
Recordset1.Source="SELECT*FROMnewsORDERBYidDESC"
Recordset1.CursorType=0
Recordset1.CursorLocation=2
Recordset1.LockType=1
Recordset1.Open()
Recordset1_numRows=0
%>
添加代码:
Recordset1.addnew
Recordset1("title")=title
Recordset1("content")=content
Recordset1.update
更新代码:
sql="updatefromVotewhereID="传递来的参数""
conn.Executesql
删除代码:
sql="deletefromVotewhereID="传递来的参数""
conn.Executesql
(4)关闭记录集
<%
Recordset1.Close()
SetRecordset1=Nothing
%>
(5)分页显示代码:
<%
DimRepeat1__numRows
DimRepeat1__index
Repeat1__numRows=3
Repeat1__index=0
Recordset1_numRows=Recordset1_numRows+Repeat1__numRows
%>
<%IfRecordset1.EOFAndRecordset1.BOFThen%>
<%EndIf%>
<%While((Repeat1__numRows<>0)AND(NOTRecordset1.EOF))%>
<%IfNotRecordset1.EOFOrNotRecordset1.BOFThen%>
要显示的内容部分………
<%EndIf%>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
目前共有<%=Recordset1.RecordCount%>条记录
从第<%=(Recordset1_first)%>条到第<%=(Recordset1_last)%>条
(6)包含文件代码:
通过包含文件可以方便的对网页进行管理操作:
--#includefile="文件路径"-->
(7)空格输出问题的解决
在
中加入代码:functionDoWhiteSpace(str)
DoWhiteSpace=Replace((Replace(str,vbCrlf,"
")),chr(32)&chr(32)," ")
EndFunction
然后在要输出的地方加入代码:
<%=DoWhiteSpace(Server.HTMLEncode(要输出的变量)%>
(8)转到详细页面:
<%
DimMM_paramNam,MM_keepNone,MM_keepURL,MM_keepFormMM_keepBoth,MM_removeList,MM_item,MM_nextItem
MM_removeList="&index="
If(MM_paramName<>"")Then
MM_removeList=MM_removeList&"&"&MM_paramName&"="
EndIf
MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""
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
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
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
FunctionMM_joinChar(firstItem)
If(firstItem<>"")Then
MM_joinChar="&"
Else
MM_joinChar=""
EndIf
EndFunction
%>
<%=Server.HTMLEncode(MM_keepNone)&MM_joinChar(MM_keepNone)&"id="&Recordset1.Fields.Item("id").Value%>">转到详细页面的链接 (9)滚动字幕实现 -- varindex=13 text=newArray(13); text[0]='' text[1]='文本内容' text[2]='文本内容' text[13]='文本内容' document.write(" for(i=0;i document.write(text[i]+" } document.write("") (10)CSS样式控制: A: link{TEXT-DECORATION: none;Color: #} A: active{TEXT-DECORATION: none;} A: visited{TEXT-DECORATION: none;} A: hover{Color: #4455aa} td{font-size: 9pt} .jianju{ letter-spacing: 2px; line-height: 200%; } 限制访问页程序: MM_authorizedUsers="admin,member" MM_authFailedURL="../Error2.ASP" MM_grantAccess=false IfSession("MM_Username")<>""Then If(falseOrCStr(Session("MM_UserAuthorization"))="")Or_ (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1)Then MM_grantAccess=true EndIf EndIf IfNotMM_grantAccessThen MM_qsChar="? " If(InStr(1,MM_authFailedURL,"? ")>=1)ThenMM_qsChar="&" MM_referrer=Request.ServerVariables("URL") if(Len(Request.QueryString())>0)ThenMM_referrer=MM_referrer&"? "&Request.QueryString() MM_authFailedURL=MM_authFailedURL&MM_qsChar&"accessdenied="&Server.URLEncode(MM_referrer) Response.Redirect(MM_authFailedURL) EndIf Board.asp中的绑定记录集分页重复区域代码,其他页所用服务器行为差不多,就不列举. DimRecordset1 DimRecordset1_numRows SetRecordset1=Server.CreateObject("ADODB.Recordset") Recordset1.ActiveConnection=MM_connboard_STRING Recordset1.Source="SELECT*FROMboardORDERBY编号DESC" Recordset1.CursorType=0 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 <% '***RecordsetStats,MoveToRecord,andGoToRecord: declarestatsvariables 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 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: ifwedon'tknowtherecordcount,manuallycountthem 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 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: handle'index'or'offset'parameter if(NotMM_paramIsDefinedAndMM_rsCount<>0)then 'useindexparameterifdefined,otherwiseuseoffsetparameter r=Request.QueryString("index") Ifr=""Thenr=Request.QueryString("offset") Ifr<>""ThenMM_offset=Int(r) 'ifwehavearecordcount,checkifwearepasttheendoftherecordset If(MM_rsCount<>-1)Then If(MM_offset>=MM_rsCountOrMM_offset=-1)Then'pastendormovelast If((MM_rsCountModMM_size)>0)Then'lastpagenotafullrepeatregion MM_offset=MM_rsCount-(MM_rsCountModMM_size) Else MM_offset=MM_rsCount-MM_size EndIf EndIf EndIf 'movethecursortotheselectedrecord i=0 While((NotMM_rs.EOF)And(i MM_rs.MoveNext i=i+1 Wend If(MM_rs.EOF)ThenMM_offset=i'setMM_offsettothelastpossiblerecord EndIf %> <% '***MoveToRecord: ifwedontknowtherecordcount,checkthedisplayrange If(MM_rsCount=-1)Then 'walktotheendofthedisplayrangeforthispage i=MM_offset While(NotMM_rs.EOFAnd(MM_size<0Ori MM_rs.MoveNext i=i+1 Wend 'ifwewalkedofftheendoftherecordset,setMM_rsCountandMM_size If(MM_rs.EOF)Then MM_rsCount=i If(MM_size<0OrMM_size>MM_rsCount)ThenMM_size=MM_rsCount 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 i=0 While(NotMM_rs.EOFAndi MM_rs.MoveNext i=i+1 Wend EndIf %> <% '***MoveToRecord: updaterecordsetstats 'setthefirstandlastdisplayedrecord Recordset1_first=MM_offset+1 Recordset1_last=MM_offset+MM_size If(MM_rsCount<>-1)Then If
");
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 asp 网站 设计 代码