asp生成静态页面编码utf-8问题

lindy258 2010-01-20 08:34:31
大家好,asp生成静态页面,生成的是unicode编码,但我需要生成的是utf-8,代码如下

Function createhtml(url,filename,path)
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
path1=server.mappath(path)&"\"&filename
Set MyTextFile=MyFileObject.CreateTextFile(path1,True,true)
strurl=url
strTmp = GetHTTPPage(trim(strurl))
MyTextFile.WriteLine(strTmp)
MytextFile.Close
Set MyFileObject=nothing
response.Write "<script language=javascript>alert('生成"&filename&"成功!');window.opener.location.reload();window.close();</script>"
End function

Function getHTTPPage(url)
On Error Resume Next
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
If Err.number<>0 then
Response.Write "<p align='center'><font color='red'><b>服务器获取文件内容出错</b></font></p>"
Err.Clear
End If
End Function

Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1'设置为可读可写
objstream.Mode =3'设置内容为文本
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset ="UTF-8"
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function

Function timetohtml(str)
timetohtml=Replace(Replace(Replace(str,":",""),"-","")," ","")&".html"
End Function

Function finddir(filepath)
finddir=""
for i=1 to len(filepath)
if left(right(filepath,i),1)="/" or left(right(filepath,i),1)="\" then
abc=i
exit for
end if
next
if abc <> 1 then
finddir=left(filepath,len(filepath)-abc+1)
end if
end Function

url="http://" & Request.ServerVariables("http_host") & finddir(Request.ServerVariables("url"))


url0=""&url&"" '这个为页面地址

path="../html"

filename="index.html"
url=url0&"list.asp"
Call createhtml(url,filename,path)


注:好像是fso不能生成utf-8编码,只能生成unicode,需要改成adodb.stream,但不知道怎么改,呵呵,大家会的帮我下哈
...全文
185 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lidanlidan 2010-01-21
  • 打赏
  • 举报
回复
Function createhtml(url,filename,path)
path1 = Server.MapPath(path) & "\" & filename
strTmp = GetHTTPPage(Trim(url))
With Server.CreateObject("ADODB.Stream")
.Type = 2
.Charset = "UTF-8"
.Open
.WriteText strTmp
.SaveToFile path1, 2
.Close
End With
End function
用这个替换你的那个
yb2008 2010-01-20
  • 打赏
  • 举报
回复
wcwtitxu 2010-01-20
  • 打赏
  • 举报
回复
Function createhtml(url,filename,path) 
path1 = Server.MapPath(path) & "\" & filename
strTmp = GetHTTPPage(Trim(url))
With Server.CreateObject("ADODB.Stream")
.Type = 2
.Charset = "UTF-8"
.Open
.WriteText strTmp
.SaveToFile path1, 2
.Close
End With
Response.Write "<script language=javascript>alert('生成"&filename&"成功!');window.opener.location.reload();window.close();</script>"
End function
aemyang1987 2010-01-20
  • 打赏
  • 举报
回复
帮顶,关注
lindy258 2010-01-20
  • 打赏
  • 举报
回复
自己顶下

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧