[30']asp向文件内写入内容完整源码
用asp向一个空白的asp文件中写入一些内容,主要是用来保存网站的站名等等基本信息的。比如现在有1.asp和2.asp,1.asp是空白文件,里面什么也没有。2.asp就...
用asp向一个空白的asp文件中写入一些内容,主要是用来保存网站的站名等等基本信息的。比如现在有1.asp和2.asp,1.asp是空白文件,里面什么也没有。2.asp就是用来向1.asp中写入内容,比如要写入
<%
a="a"
b="b"
%>
那么2.asp的代码是什么??
要具体完整的源码!希望高手赐教!!
新手先谢过了!!!
一楼的太复杂了。二楼这样做是为了减轻一下数据库的压力访问速度。一些信息可以直接从文件读取。
三楼运行时显示 ts.write(html) 无效的过程调用或参数
唉~~~~ 展开
<%
a="a"
b="b"
%>
那么2.asp的代码是什么??
要具体完整的源码!希望高手赐教!!
新手先谢过了!!!
一楼的太复杂了。二楼这样做是为了减轻一下数据库的压力访问速度。一些信息可以直接从文件读取。
三楼运行时显示 ts.write(html) 无效的过程调用或参数
唉~~~~ 展开
3个回答
展开全部
<%
on error resume next
Server.ScriptTimeOut=10
user=request.QueryString("u")
if user="" then
response.end
end if
frm=request.QueryString("frm")
Call CreateFolder(user)
Call ct_wj()
'==================================================
'函数名:GetHttpPage
'作 用:获取网页源码
'参 数:HttpUrl ------网页地址,Cset 编码
'==================================================
Function GetHttpPage(ByVal URL, ByVal Cset)
Dim Http
If IsNull(URL)=True Or Len(URL)<10 Then Exit Function
if InStr(LCase(Url),"http://")=0 then
if Left(Url,1)<>"/" then Url= "/" & Url
Url= "http://" & Request.ServerVariables("SERVER_NAME") & Url
end if
'Microsoft.XMLHTTP 'MSXML2.XMLHTTP
'MSXML2.ServerXMLHTTP.3.0 'MSXML2.ServerXMLHTTP.4.0 'MSXML2.ServerXMLHTTP.2.6
'On Error Resume Next
Set Http=server.createobject("MSXML2.XMLHTTP")
if not IsObject(Http) then Http=server.createobject("Microsoft.XMLHTTP")
if not IsObject(Http) then Http=server.createobject("MSXML2.ServerXMLHTTP.3.0")
if not IsObject(Http) then Http=server.createobject("MSXML2.ServerXMLHTTP.4.0")
if not IsObject(Http) then Http=server.createobject("MSXML2.ServerXMLHTTP.2.6")
if not IsObject(Http) then
Response.Write "服务器可能不支持 XMLHTTP,请检查"
Response.End
End if
Http.open "GET",URL,False
Http.Send()
If Http.Readystate=4 then
GetHTTPPage=bytesToBSTR(Http.responseBody,Cset)
End if
Set Http=Nothing
End Function
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
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 = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Sub ct_wj()
txtURL= "test.asp" '要输出的内容,格式化下,在test.asp文件里
sText = getHTTPPage(txtURL,"GB2312")
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename="1.asp"
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
End Sub
'创建文件夹
function CreateFolder(FolderName)
'on error resume next
fldr=server.MapPath(FolderName)
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'response.Write(fldr)
If Not fso.FolderExists(fldr) Then
fso.CreateFolder(fldr)
End If
Set fso = Nothing
end function
function ISuser(FolderName)
fldr=server.MapPath(FolderName)
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fldr) Then
fso.CreateFolder(fldr)
End If
Set fso = Nothing
end function
function ISpoor(str)
'on error resume next
'str=server.MapPath(fileDir)
'str = "user/bba"
str=server.MapPath(str)
Set fs = CreateObject("Scripting.FileSystemObject")
set folder=fs.getfolder(str)
'set folders=folder.SubFolders
'set files=folder.files
if folder.size = 0 then
ISpoor = true
'response.Write("文件夹为空!")
else
ISpoor = false
'response.Write("文件夹不为空!")
end if
end function
'===============判断文件夹是否存在
function IsFolderTrue(FolderName)
fldr=server.MapPath(FolderName)
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fldr) Then
IsFolderTrue=False
'response.Write("文件夹"&fldr&"不存在")
Else
IsFolderTrue=True
'response.Write("文件夹"&fldr&"已存在")
End If
Set fso = Nothing
end function
'===============判断文件是否存在
Function IsFileTrue(FileName)
flnm=server.MapPath(FileName)
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'response.Write(fldr)
If Not fso.FileExists(flnm) Then
'不存在文件
IsFileTrue = False
'response.Write("<br>文件"&flnm&"不存在")
Else
IsFileTrue = True
'response.Write("<Br>文件"&flnm&"已存在")
End If
Set fso = Nothing
End Function
Sub client_alert(ByVal str, ByVal stype)
response.Clear
response.write "<html>" & vbCrLf
response.write "<head>" & vbCrLf
response.write "<meta http-equiv=""content-type"" content=""text/html; charset=gb2312"">" & vbCrLf
response.write "<title>网站QQ在线咨询-提示信息</title>" & vbCrLf
response.write "</head>" & vbCrLf
response.write "<body>" & vbCrLf
response.write "<script language=""javascript"">" & vbCrLf
response.write "alert(""" & str & """)" & vbCrLf
If IsNumeric(stype) Then
response.write "history.go(" & stype & ")" & vbCrLf
Else
response.write "location.href=""" & stype & """" & vbCrLf
End If
response.write "</script>" & vbCrLf
response.write "</body>" & vbCrLf
response.write "</html>" & vbCrLf
response.End
End Sub
'========================FSO创建文件
Sub fso_write(ByVal fpath, ByVal ftext)
On Error Resume Next
Dim fso, fout
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(Server.MapPath(fpath))
fout.write ftext
fout.Close
Set fout = Nothing
Set fso = Nothing
If Err Then
Call client_alert("创建文件失败,可能是您的服务器不支持FSO权限而导致的!",-1)
End If
End Sub
%>
上边的是2.asp的文件,这里需要一个test.asp,目的是输出把test.asp的内容写入到1.asp里边,
test.asp
<%
repsonse.write("<%")
response.write("a='a'<Br>")
response.write("b='b'<Br>")
response.write("%>")
%>
试试,如果 %>输出不了的话,就想办法对<>进行转义.(<> < >)
on error resume next
Server.ScriptTimeOut=10
user=request.QueryString("u")
if user="" then
response.end
end if
frm=request.QueryString("frm")
Call CreateFolder(user)
Call ct_wj()
'==================================================
'函数名:GetHttpPage
'作 用:获取网页源码
'参 数:HttpUrl ------网页地址,Cset 编码
'==================================================
Function GetHttpPage(ByVal URL, ByVal Cset)
Dim Http
If IsNull(URL)=True Or Len(URL)<10 Then Exit Function
if InStr(LCase(Url),"http://")=0 then
if Left(Url,1)<>"/" then Url= "/" & Url
Url= "http://" & Request.ServerVariables("SERVER_NAME") & Url
end if
'Microsoft.XMLHTTP 'MSXML2.XMLHTTP
'MSXML2.ServerXMLHTTP.3.0 'MSXML2.ServerXMLHTTP.4.0 'MSXML2.ServerXMLHTTP.2.6
'On Error Resume Next
Set Http=server.createobject("MSXML2.XMLHTTP")
if not IsObject(Http) then Http=server.createobject("Microsoft.XMLHTTP")
if not IsObject(Http) then Http=server.createobject("MSXML2.ServerXMLHTTP.3.0")
if not IsObject(Http) then Http=server.createobject("MSXML2.ServerXMLHTTP.4.0")
if not IsObject(Http) then Http=server.createobject("MSXML2.ServerXMLHTTP.2.6")
if not IsObject(Http) then
Response.Write "服务器可能不支持 XMLHTTP,请检查"
Response.End
End if
Http.open "GET",URL,False
Http.Send()
If Http.Readystate=4 then
GetHTTPPage=bytesToBSTR(Http.responseBody,Cset)
End if
Set Http=Nothing
End Function
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
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 = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Sub ct_wj()
txtURL= "test.asp" '要输出的内容,格式化下,在test.asp文件里
sText = getHTTPPage(txtURL,"GB2312")
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename="1.asp"
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
End Sub
'创建文件夹
function CreateFolder(FolderName)
'on error resume next
fldr=server.MapPath(FolderName)
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'response.Write(fldr)
If Not fso.FolderExists(fldr) Then
fso.CreateFolder(fldr)
End If
Set fso = Nothing
end function
function ISuser(FolderName)
fldr=server.MapPath(FolderName)
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fldr) Then
fso.CreateFolder(fldr)
End If
Set fso = Nothing
end function
function ISpoor(str)
'on error resume next
'str=server.MapPath(fileDir)
'str = "user/bba"
str=server.MapPath(str)
Set fs = CreateObject("Scripting.FileSystemObject")
set folder=fs.getfolder(str)
'set folders=folder.SubFolders
'set files=folder.files
if folder.size = 0 then
ISpoor = true
'response.Write("文件夹为空!")
else
ISpoor = false
'response.Write("文件夹不为空!")
end if
end function
'===============判断文件夹是否存在
function IsFolderTrue(FolderName)
fldr=server.MapPath(FolderName)
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fldr) Then
IsFolderTrue=False
'response.Write("文件夹"&fldr&"不存在")
Else
IsFolderTrue=True
'response.Write("文件夹"&fldr&"已存在")
End If
Set fso = Nothing
end function
'===============判断文件是否存在
Function IsFileTrue(FileName)
flnm=server.MapPath(FileName)
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'response.Write(fldr)
If Not fso.FileExists(flnm) Then
'不存在文件
IsFileTrue = False
'response.Write("<br>文件"&flnm&"不存在")
Else
IsFileTrue = True
'response.Write("<Br>文件"&flnm&"已存在")
End If
Set fso = Nothing
End Function
Sub client_alert(ByVal str, ByVal stype)
response.Clear
response.write "<html>" & vbCrLf
response.write "<head>" & vbCrLf
response.write "<meta http-equiv=""content-type"" content=""text/html; charset=gb2312"">" & vbCrLf
response.write "<title>网站QQ在线咨询-提示信息</title>" & vbCrLf
response.write "</head>" & vbCrLf
response.write "<body>" & vbCrLf
response.write "<script language=""javascript"">" & vbCrLf
response.write "alert(""" & str & """)" & vbCrLf
If IsNumeric(stype) Then
response.write "history.go(" & stype & ")" & vbCrLf
Else
response.write "location.href=""" & stype & """" & vbCrLf
End If
response.write "</script>" & vbCrLf
response.write "</body>" & vbCrLf
response.write "</html>" & vbCrLf
response.End
End Sub
'========================FSO创建文件
Sub fso_write(ByVal fpath, ByVal ftext)
On Error Resume Next
Dim fso, fout
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(Server.MapPath(fpath))
fout.write ftext
fout.Close
Set fout = Nothing
Set fso = Nothing
If Err Then
Call client_alert("创建文件失败,可能是您的服务器不支持FSO权限而导致的!",-1)
End If
End Sub
%>
上边的是2.asp的文件,这里需要一个test.asp,目的是输出把test.asp的内容写入到1.asp里边,
test.asp
<%
repsonse.write("<%")
response.write("a='a'<Br>")
response.write("b='b'<Br>")
response.write("%>")
%>
试试,如果 %>输出不了的话,就想办法对<>进行转义.(<> < >)
展开全部
<%
'你如果只要写入文件就用这个
set fso=server.createobject("Scripting.FileSystemObject")'这个对象就是写入和创建文件的
'---------------------------
checkfiles=server.mappath("about.txt")
if (fso.fileexists(checkfiles)) then '检查一下文件在不在,在就删除
set delfile=fso.getfile(checkfiles)
delfile.delete
end if
'------------------------------
files=server.mappath("about.txt")'你要存储的文件名
html="要写入的文字内容"
set ts = fso.createtextfile(files,false)
ts.write(html) '写入文件
ts.close
set ts=nothing
set fso=nothing
response.write("<script>alert(""创建并写入成功!"");</script>")
%>
----------------其实用PHP最简单了,几句就搞定----------------------
<?php
$url="http://www.163.com/";
$str=@file_get_contents($url);
$file = fopen("test.html","w");
//echo fwrite($file,$str);
fclose($file);
?>
---------------------------------------------------
'你如果只要写入文件就用这个
set fso=server.createobject("Scripting.FileSystemObject")'这个对象就是写入和创建文件的
'---------------------------
checkfiles=server.mappath("about.txt")
if (fso.fileexists(checkfiles)) then '检查一下文件在不在,在就删除
set delfile=fso.getfile(checkfiles)
delfile.delete
end if
'------------------------------
files=server.mappath("about.txt")'你要存储的文件名
html="要写入的文字内容"
set ts = fso.createtextfile(files,false)
ts.write(html) '写入文件
ts.close
set ts=nothing
set fso=nothing
response.write("<script>alert(""创建并写入成功!"");</script>")
%>
----------------其实用PHP最简单了,几句就搞定----------------------
<?php
$url="http://www.163.com/";
$str=@file_get_contents($url);
$file = fopen("test.html","w");
//echo fwrite($file,$str);
fclose($file);
?>
---------------------------------------------------
参考资料: 自己写的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一个数据库文件解决问题,2.asp把内容写进数据库,1.asp负责读取数据库的信息就行了,很简单事情干嘛搞那么复杂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询