確認條件
1. 網頁是 Big5 編碼
2. 資料庫是 utf-8 編碼
3. 網頁結構不是 utf-8
符合以上條件,在網頁開頭加入以下語法即可避免亂碼
<% Session.CodePage="950" %>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
| 2010/05/25 11:41 |
[網頁程式/ASP] 的文章列表 ....6 篇文章 在 Big5 網頁開啟 utf-8 資料庫避免亂碼的方法如下:
確認條件 1. 網頁是 Big5 編碼 2. 資料庫是 utf-8 編碼 3. 網頁結構不是 utf-8 符合以上條件,在網頁開頭加入以下語法即可避免亂碼 <%@ LANGUAGE="VBSCRIPT" CODEPAGE="950" %> <% Session.CodePage="950" %> <meta http-equiv="Content-Type" content="text/html; charset=big5">
最近嘗試由 ASP 連接 MySQL,發現一些問題是 ASP + MSSQL 沒遇過的,統一整理如下:
這裡介紹以文字檔作記錄的計數器製作方法,紅色部份是以 Session 管制計數器不在重新整理時自動 +1 ,可視情況使用。
count.txt 0 count.asp <% CountFile = Server.MapPath("count.txt") '開啟檔案 set Object = Server.CreateObject("Scripting.FileSystemObject") '呼叫檔案處理元件 set file1= Object.OpenTextFile(CountFile, 1, false, false) '設定檔案為唯讀 counter = file1.ReadLine '讀取檔案 file1.Close '關閉檔案 if isempty(Session("connected")) then '紅色部份可管制計數器在重新整理不會增加 set Object = Server.CreateObject("Scripting.FileSystemObject") '呼叫檔案處理元件 set file1= Object.CreateTextFile (CountFile, true, false) '設定寫入時覆蓋原檔案 Application.lock '鎖定 Application 物件 counter= counter + 1 '將計數器加1 file1.WriteLine(counter) '將資料寫入檔案 Application.unlock '解鎖 Application 物件 file1.Close '關閉檔案 Session("connected") = true end if response.write counter '完成計數器 '-----------------------------------------以下動作只是要將計數器前面補上0 response.write "<p>" count_len = len(counter) '計數器目前字數 count_full = 5 '設定計數器為五位數 for i=1 to count_full - count_len '補滿0 txt1 = "0" + txt1 next do while count_len > 0 '計數器數字 txt2 = mid(counter, count_len, 1) + txt2 count_len = count_len - 1 loop txt = txt1 + txt2 '加在一起 response.write txt '完成有補0的計數器 %>
ASP 經常需要指定檔案的絕對路徑 (絕對路徑例 C:\web )
如果你不知道主機的絕對路徑,你可以用以下的語法: path.asp <%= Server.MapPath("/") %>
PHP 有個顯示環境資訊的函數 phpinfo(),那麼 ASP 呢?
這裡介紹簡單的 ASP 環境資訊顯示方法: aspinfo.asp <% for each info in request.ServerVariables response.write info & " = " & request.ServerVariables(info) & "<p>" next %>
在這裡要介紹使用 CDONTS.Newmail 這個組件,透過 IIS 發送信件的方法,Demo 的平台是 WindowsXP Pro。
準備工作: 1. 首先要查看 C:\WINDOWS\system32 目錄下有沒有 cdonts.dll 這個檔案,沒有找到的話,請到 DLL World ,搜尋 cdonts.dll 並下載。 2. 開始 > 執行,輸入 regsvr32 cdonts.dll ,以註冊 CDONTS 組件。 3. 控制台 > 系統管理工具 > Internet Information Services,啟動預設 SMTP 虛擬伺服器。 現在你的 IIS 可以使用 CDONTS.Newmail 組件了!為了更容易懂,只介紹此組件的入門語法: my_mail.asp <% 只要開啟或 Refresh 這個網頁,它就會發一封信到你指定的 Email。用 ASP 發信其實不難吧..dim my_mail set my_mail=server.Createobject("CDONTS.NewMail") my_mail.from="寄件人姓名<寄件人Email>" my_mail.to="收件人姓名<收件人Email>" my_mail.subject="測試主旨" my_mail.body="測試內文" my_mail.send set my_mail=nothing %> 相關連結:CDONTS.Newmail 進階語法
|