ASP資料收集
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
1.Asp 對(duì)象與內(nèi)置組件
1.1 Response resPonse.write "html語句" response.redirect "url" response.writeBinary Variable (圖像資料) response.end response.clear response.Flush response.AppenTLog "Information" ->iis login file response.buffer=true/false -> 馬上解釋馬上顯示 response.ContentType="text/html" "image/gif" response.CharSet "gb2312" response.expirse=n 分 (0) response.ExpireAbsolute=#9,2000 8:30:30# response.status="403 Forbidden" ResPonse.Cookies(cookie)[key]|(.attribute)=value .cookies() 的屬性.Domain .expires 到期時(shí)間 .HasKeys .Path response.cookies("University")="TsingHua" response.cookies("university").expires="January,1,2001" response.cookies("university").("TsingHua")="January" 一個(gè)可有多值 1.2 Request Request.form("ID") request.querystring("ID") 1.3 Server變量和方法 ServerVariables For each name in Request.ServerVariables response.write("<br>"&name&"="&Request.serverVariables(name) next Server.method server.createobject() server.mappath() server.HtmEncode("<html>") 不會(huì)被解釋 server.urlEncode("url") 1.4 Session session.collection|Property|method <%@ EnableSessionstate=False%> session.SessionID (會(huì)話標(biāo)識(shí)) session.Timeout (分鐘為單位) session.Abandon (破壞釋放) for i=1 to Session.Contents.Count Response.write("<br>"&Session.contents(i)) next 1.5 Application Application("aa")="aa" set Application("My")=server.createobject("MYcomponent") global.asa <script language=Vbscript runat=server> sub Application_onStart Applicaiton.lock Application("All")=0 Application("OnLine")=0 Application.unlock end sub Sub session_Onstart Application.lock Application("Online")= Application("ONline")+1 Application("all")= Application("all")+1 Application.unlock end Sub sub session_onend Application.lock Application("Online")=Application("Online")-1 end sub Sub Application_Onend end sub </script> 1.6 內(nèi)置組件 略 2.使用瀏覽器的能力 [browscap.ini 文件最新] <%set Mybrow=server.createobject("mswc.browserType") aa=mybrow.browser %> browser: 瀏覽器類型 version: 版本號(hào) majorver: 主版本 miorver: 輔版本 frames: 支持分屏 tables: 支持表格 cookies: 支持cookies backgroundsounds:支持bgsound vbscript: 支持否 javascripts: 支持否 javaapplets: 支持否 activexcontrols: 支持否 beta: 是否是測(cè)試版 platform: os win16: 16(win31) 32(win95 winnT) 3.文件存取 File Access: 1 FilesystemObject 文件系統(tǒng)基本方法 2 textstream 讀寫文本文件 3 file 處理單個(gè)文件 4 folder 處理文件夾 5 drive 磁盤驅(qū)動(dòng)器與網(wǎng)絡(luò)共享 File Access Component: 1 Files 文件夾中一系列文件 2 Folder 3 Drive 文件讀寫 <% set Fobject=server.createobject("scripting.FilesystemObject") set Tfile=Fobject.CreateTextFile("aa.txt") """"" set Tfile=Fobject.opentextfile """"" while not Tfile.atEndofStream """"" response.write (tFIle.readline) """"" wend Tfile.writeline("hellp") Tfile.close %> CreateTextFile(filename,[Overwrite(true/False)[,unicode]]) Opentextfile(filename[,Mode] [,Create] [,Format]) mode:1 ForReading , 8 ForAppending Create 文件不存在是否創(chuàng)建 true/false format -2 默認(rèn), -1 unicode , 0 ASCII textstream的屬性 和 方法 atendofLine Read(N) atendofstream ReadLine() column ReadAll line Skip(n) Close 文件的處理 set Fileobject=server.createobject(scripting.FileSystemOjbect) set Tfile=Fileobject.opentextfile("aa.txt") 或者 set Tfile=FileObject.getFile("aa.txt") FilesystemObject 方法 File 方法 File 屬性 Fileobject.copyFile "aa.txt" "bb.txt" Tfile.copy "bb.txt" attributes 0 normal ,1 read-only Fileobject.MoveFile "aa.txt" "bb.txt" Tfile.move "bb.txt" 2 hidden ,4 system 8 volume, Fileobject.deleteFile "aa.txt" Tfile.delete 16 directory ,32 archive 64 alias ,128 compressed dateCreated 創(chuàng)建日期 DateLastAccessed 最后訪問日期 DateLastModified 最后修改日期 Drive 驅(qū)動(dòng)器 name 文件名 ParentFolder 所在文件夾 path 全路徑 size 文件字節(jié)數(shù) type 文件類型 FileSystemObject 的方法 set FileObject=server.createobject(scripting.Filesystemobject) FileObjet.FileExists(fileName) FileObjet.GetFile(fileName) Myfileobject.DirveExists("c:") Myfileobject.GetDrive("C:") Myfileobject.getDriveName(path) Fileobject.CopyFolder "c:\aa" "d:\bb" Fileobject.DeleteFolder "c:\aa" Fileobject.FolderExists ("c:\aa") Fileobject.GetFolder("c:\") Fileobject.MoveFolder("c:\") 4.驅(qū)動(dòng)器的操作與文件夾的操作 <%set myfileobject=server.createobject("scripting filesystemObject") for each thing in myfileobject.driver %> thing.driverletter thing.totalsize thing.availablespace next 'FilesystemObject 方法 Myfileobject.DirveExists("c:") Myfileobject.GetDrive("C:") Myfileobject.getDriveName(path) 'driver 方法 set Dir=FileSystemobject.getDrive("C:") dir.AvailableSpace() '可用空間 dir.driverletter 'drive name dir.DriveType 'cd-rom removeable drive dir.serialNumber 'serialNumber dir.totalsize dir.shareName dir.VolumnName 'FilesystemObject 方法 Fileobject.CopyFolder "c:\aa" "d:\bb" Fileobject.DeleteFolder "c:\aa" Fileobject.FolderExists ("c:\aa") Fileobject.GetFolder("c:\") Fileobject.MoveFolder("c:\") 'Folder 方法 set Fol=FileSystemObject.getFolder("c:\MyFile") for each thing in Fol.Files response.write ("<p>"&thing) ' next Fol.copyFolder "d:\bb" [,overwrite] Fol.DeleteFolder Fol.Files Fol.name Fol.moveFolder "c:\aa" 5.郵件發(fā)送 [ smtp service ] asp 發(fā)送email sub sendMail(fromwho,towho,subject,body) dim mymail set mymail=server.createobject("CDONTS.Newmail") Mymail.From=FromWho Mymail.To=Towho Mymail.Subject=Subject MyMail.Body=body 'Mymail.AttachFile thispage "source" Mymail.cc="d@d.com" '抄送 Mymail.bcc="a@a.com;b@b.com;c@c.com" '密送 Mymail.Sendset set Mymail=NOthing end sub 'FromWho=trim(reauest.form("fromWho")) '... '... 'If towho<>"" then ' SendMail fromwho,towho,subject,body 'end If 6.Ado 主要對(duì)象 1 Connection: 2 Command 3 Recordset 4 Error 5 Parameter 6 Property 7 Field SET CONN=SERVER.CREATEOBJECT("ADODB.CONNECTION") 'SET RS=SERVER.CREATEOBJECT("ADODB.RECORDSET") 'SET COMM=SERVER.CREATEOBJECT("ADODB.COMMAND") CONN.OPEN "DSN=HELLO" SET RS=CONN.EXECUTE(SQLLANGUAGE) ' n,n | 1,3 WHILE RS.EOF RS.MOVENEXT RS.MOVEFIRST RS.MOVELAST RS.MOVEPREVIOUS RS.MOVE NUMBER WEND 'RS.move,RS.BOF RS.EOF 'RS.RecordCount RS.PageCount RS.PageSize RS.MaxRecords 'RS.AbsolutePage .RS.CursorLocation=3 RS.AbsolutePosition [位置順序號(hào)] 要配合使用 'rs("fieldname") rs(Number) rs.Fields("fieldname") rs.Fields(Number) 'Rs.Fields.Item("fieldname") Rs.Fields.item(Number) 關(guān)于Connection 與 Command Set Conn=Server.CreateObject("Adodb.Connection") Set MyCommand=server.createObject("Adodb.Command") Conn.open "DSN=Hello" Set Mycommand.activeConnection=Conn Mycommand.CommandType=adCMDText Mycommand.CommandText="select * from tablename" set Rs=Mycommand.Execute() Rs.close conn.close 關(guān)于 RecordSet 與 Command Set Conn=Server.CreateObject("Adodb.Connection") Set MyCommand=server.createObject("Adodb.Command") SET RS=SERVER.CREATEOBJECT("ADODB.RECORDSET") Conn.open "DSN=Hello" Set Mycommand.activeConnection=Conn Mycommand.CommandType=adCMDText Mycommand.CommandText="select * from tablename" Rs.open Mycommand,adOpenStatic,adLockOptimstic Rs.close conn.close COMMAND 帶參數(shù)存儲(chǔ)過程 略 不用DSN訪問數(shù)據(jù)源 Connection to Access: " Driver={Microsoft Access Driver (*.mdb)} ;DBQ="& server.mappath("aa.mdb")&"uid=;pwd=;" Connection to Vfp: DBC DBF Connection to SQL: " Driver={Sql Server};Server=carl2; DataBase=pubs; uid=sa;pwd=;" Connection to ORCale: " Driver={Microsoft ODBC for Orcale};server=OrcaleServer.world; uid=demo;pwd=demo;" 該文章在 2013/11/28 11:43:01 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |