网页静态化可以减轻服务器负担、提高页面打开打开速度、利于搜索引擎优化(SEO)。
本文记录了ASP如何实现网页静态化应用。
- 收藏家 - 收罗天下:软件、素材、资讯,共享收藏
DBClass.asp
<%
Class DBClass
Private connectionString
Private conn
Private Sub Class_Initialize()
End Sub
Private Sub Class_Ierminate()
End Sub
Public Property Let ConnStr(ByVal vNewValue)
connectionString= vNewValue
End Property
Public Property Get ConnStr()
ConnStr = connectionString
End Property
Private Sub Open()
On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open ConnStr
If (Err) Then
err.Clear
Set conn = Nothing
Response.Write "DataBase Open Error"
Response.End
End If
End Sub
Public Sub Close()
On Error Resume Next
conn.Close
set conn = nothing
End Sub
Public Function Execute(sql)
On Error Resume Next
Open
Set Execute = conn.Execute(sql)
If (Err) Then
err.Clear
Close
Response.Write "Execute Error"
Response.End
End If
End Function
End Class
%>
Fun.asp
<%
Function FilterChar(sql)
Dim c
c = sql
c = replace(c,"'", "''")
c = replace(c,"[", "[[]")
c = replace(c,"_", "[_]")
c = replace(c,"%", "[%]")
FilterChar = c
End Function
Function ReadFile(file)
Dim stm
Set stm = Server.CreateObject("ADODB.Stream")
stm.Charset="utf-8"
stm.Open
stm.LoadFromFile Server.MapPath(file)
ReadFile = stm.ReadText
Set stm=Nothing
End Function
Sub CreateFile(fileName,content)
Dim stm
Set stm = server.CreateObject("ADODB.Stream")
With stm
.Open
.Charset = "utf-8"
.Position = stm.Size
.WriteText = content
.SaveToFile Server.MapPath(fileName),2
.Close
End With
Set stm = Nothing
End Sub
Function FormatDT(date,style)
Dim y,m,d,h,min,sec
If (Not IsDate(date)) Then
FormatDT = ""
Exit Function
End If
y = CStr(Year(date))
m = CStr(Month(date))
d = CStr(Day(date))
h = CStr(Hour(date))
min = CStr(Minute(date))
sec = CStr(Second(date))
If (Len(m)=1) Then m = "0" & m
If (Len(d)=1) Then d = "0" & d
If (Len(h)=1) Then h = "0" & h
If (Len(min )=1) Then min = "0" & min
If (Len(sec)=1) Then sec = "0" & sec
If (style = "yyyy-MM-dd") Then
FormatDT = y & "-" & m & "-" & d
Exit Function
End If
If (style = "yyyy-MM-dd hh:mm:ss") Then
FormatDT = y & "-" & m & "-" & d & " " & h & ":" & min & ":" & sec
Exit Function
End If
If (style = "MM-dd") Then
FormatDT =m & "-" & d
Exit Function
End If
FormatDT = date
End Function
Function FilterSql(sql)
FilterSql = replace(sql,"'","''")
End Function
Function OutputHtml(str)
If (IsNull(str)) Then
OutputHtml = ""
Exit Function
End If
str = replace(str, "&", "&")
str = replace(str, "<", "<")
str = replace(str, ">", ">")
str = replace(str, Chr(32), " ")
str = replace(str, Chr(13), "
")
OutputHtml = str
End Function
Function GetByteLength(str)
If (IsNull(str)) Then
GetByteLength = ""
Exit Function
End If
Dim x,y,i
x = Len(str)
y = 0
For i=1 To x
If (Asc(Mid(str,i,1)) < 0 or Asc(Mid(str,i,1)) > 255) Then
y = y + 1
Else
y = y + 2
End If
Next
GetByteLength = y
End Function
Function GetTextByByteLength(str,byteLength)
Dim x,y,i,s
s = ""
x = Len(str)
y = 0
If (x >= 1) Then
For i = 1 To x
s = s & Mid(str,i,1)
If (GetByteLength(s) > byteLength) Then
s = Mid(str,1,Len(S)-1)
Exit For
End If
Next
End if
If ((GetByteLength(str) > byteLength) and (GetByteLength(s) > 3)) Then
Dim dotLen
dotLen = 0
For i = Len(s) To 1 Step -1
dotLen = dotLen + GetByteLength(Mid(s,i,1))
If (dotLen >= 3) Then
's = Mid(s,1,i) & "..."
Exit For
End If
Next
End If
GetTextByByteLength= s
End Function
Function BToKMB(softSize)
softSize = CDbl(softSize)/1024
If (softSize < 1024) Then
softSize = Mid(CStr(softSize),1,InStr(CStr(softSize),".")+2) & "KB"
Else
softSize = softSize/1024
softSize = Mid(CStr(softSize),1,InStr(CStr(softSize),".")+2) & "MB"
End If
BToKMB = softSize
End Function
%>
完整笔记:http://www.laobingbiji.com/note/detail.html?note_id=202311212000270000000010173589