不忘初心,不负韶华,砥砺前行!
Pages: 1/2 First page 1 2 Next page Final page [ View by Articles | List ]
2月27

ASP生成JSON数据

09:39ASP  From: Original

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="json.asp"-->
<!--#include file="inc/Conn.asp" -->
<%
response.ContentType="text/json"
dim j

'多重嵌套的JSON,要使用Dictionary才能实现
set j=new json
j.toResponse=false
set r=server.createobject("scripting.dictionary")
set b=server.createobject("scripting.dictionary")
set c=server.createobject("scripting.dictionary")
c.add "x",5
c.add "y",6
c.add "z",11
b.add "event","Mouse Click"
b.add "data",c
r.add "success",true
r.add "result",b
a=j.toJSON(empty,r,false)
response.write a

'记录集转为Json
set i=new json
i.toresponse=false
set rs=server.CreateObject("adodb.recordset")
sqlstr="select top 5 * from producttype"
rs.open sqlstr,conn,0,1
v=i.toJson("result",rs,false)
rs.close
response.write v
%>

要注意的是:

1,嵌套的JSON是要用DICTIONARY来生成的,其他的方法,我还没有找到

2,最终的结果在输出时,可以用toJson(empty,r,false)这种形式,这样,生成的JSON,就不会类似{var:{var1:'',var2:''}}这种形式,而是直接的:{var1:'',var2:''},这种格式在我们用来处理表单,返回数据时,一定要注意

3,生成JSON的ASP页面,输出格式,解析JSON的JS文件,HTML页面,必须全是UTF-8格式编码,一个环节编码不正确,就会导致接收到的JSON在显示中文时变乱码
4月10

asp防盗链函数代码

11:50ASP  From: Original
如何隐藏下载地址及防盗链,看以下的“asp防盗链函数代码”

<% FunctIon DownloadFIle(StrFIle)
StrFIlename=StrFIle
Response.Buffer=True
Response.Clear
Set S=Server.CreateObJect("ADODB.Stream")
S.Open
S.Type=1
on Error Resume Next
Set Fso=Server.CreateObJect("ScrIptIng.FIleSystemObJect")
If Not Fso.FIleExists(StrFIleName) Then
From_Url=Cstr(Request.ServerVarIables("HTTP_REFERER"))
Serv_Url=Cstr(Request.ServerVarIables("SERVER_NAME"))
If MId(From_Url,8,len(Serv_Url)) <> Serv_Url Then
Response.WrIte "该文件不存在或者已经删除."
Response.End
End If
Response.RedIrect Request.ServerVarIables("HTTP_REFERER")
Response.End
End If
FileExt=MId(StrFIlename,InStrRev(StrFIleName, ".")+1)
Select Case UCase(FIleExt)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB", "PHP", "JSP", "SHTML", "HTML", "HTM", "TV", "DATA"
From_Url=Cstr(Request.ServerVarIables("HTTP_REFERER"))
Serv_Url=Cstr(Request.ServerVarIables("SERVER_NAME"))
If MId(From_Url,8,len(Serv_Url)) <> Serv_Url Then
Response.WrIte "该文件不存在或者已经删除."
Response.End
End If
Response.RedIrect Request.ServerVarIables("HTTP_REFERER")
Response.End
End Select
Set F=Fso.GetFIle(StrFIlename)
IntFIlelength=F.SIze
s.LoadFromFIle(StrFIlename)
If Err Then
From_Url=Cstr(Request.ServerVarIables("HTTP_REFERER"))
Serv_Url=Cstr(Request.ServerVarIables("SERVER_NAME"))
If MId(From_Url,8,len(Serv_Url)) <> Serv_Url Then
Response.WrIte "该文件数据不完整或许已损坏."
Response.End
End If
Response.RedIrect Request.ServerVarIables("HTTP_REFERER")
Response.End
End If
Set Upload=Server.CreateObJect("PersIts.Upload")
If Upload Is Nothing Then
Response.AddHeader "Content-DIsposItIon","attachment; FIlename="&F.Name
Response.AddHeader "Content-Length",IntFilelength
Response.CharSet="UTF-8"
Response.ContentType="application/x-download"
Response.BinaryWrite S.Read
Response.Flush
S.Close
Set s=NothIng
Else
Upload.SendBinary StrFIlename,True,"application/x-download",False
End If
End FunctIon
%>


使用

<%Call DownloadFIle("下载地址")%>
11月8
我们经常会遇到多重查询问题,而长长的SQL语句往往让人丈二和尚摸不着头脑。特别是客户端部分填入查询条件时,如用普通方法将更是难上加难。
以下巧妙地利用"where 1=1"的恒等式(事实上很多,让它值为TRUE即可)解决此问题。
8月28
把xls文件当成数据库,里面的表作为数据库的表来看待,第一行看成是数据库表的字段名。
管理这个需要服务器上有一个空的XLS文件,你可以使用FTP传上。
显示数据
Set conn=Server.CreateObject("ADODB.Connection")
conn.open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &Server.MapPath("test.xls")&";Extended Properties=Excel 8.0;"
set rs=server.createobject("adodb.recordset")
sql="select * from [Sheet1$]"
rs.open sql,conn,1,1

添加数据
conn.execute("insert into [Sheet1$](字段名) values('值') ")


缺点就是 删除和修改就比较麻烦了,需要自己多动动脑了,呵呵!。
8月28

简单的asp生成html代码

12:05ASP  From: Original

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>

<body>
<%
call CreateHtml("../index.asp","/index.html")
Function CreateHtml(RemoteFileUrl,LocalFileName)
dim objXmlHttp
set objXmlHttp = Server.CreateObject("Micr"&"oso"&"ft.XM"&"LHT"&"TP")

'后台目录url
http=request.ServerVariables("HTTP_REFERER")
http=Mid(http,1,InStrRev(http,"/"))
if InStr(lcase(RemoteFileUrl),"http://")<=0 then
RemoteFileUrl=http&RemoteFileUrl
end if

if instr(RemoteFileUrl,"?")>0 then
RemoteFileUrl2=RemoteFileUrl&"&getkey_n="&getkey_n(6)
else
RemoteFileUrl2=RemoteFileUrl&"?getkey_n="&getkey_n(6)
end if

objXmlHttp.open "GET",RemoteFileUrl2,false
objXmlHttp.send()
Dim binFileData
binFileData = objXmlHttp.responseBody
Dim objAdoStream
set objAdoStream = Server.CreateObject("ADO"&"DB.Str"&"eam")
objAdoStream.Type = 1
objAdoStream.Open()
objAdoStream.Write(binFileData)
objAdoStream.SaveToFile server.MapPath(LocalFileName),2
objAdoStream.Close()
response.write("生成:<a href="""&LocalFileName&""" target=""_blank"">"&LocalFileName&"</a> 成功!<br/>"&vbcrlf)
response.Flush()
End Function

'随机数字
Function getkey_n(digits)
dim char_array(50),output,num
output=""
char_array(0) = "0"
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
randomize
do while len(output) < digits
num = char_array(Int((9 - 0 + 1) * Rnd + 0))
output = output + num
loop
getkey_n = output
End Function
%>
</body>
</html>


保存为 asp 文件 放到 admin目录下,运行就可以生成首页了。

调用 call CreateHtml("../index.asp","/index.html") 可以进行相应的修改

第一个参数为相对路径 也可以用绝对路径(http://...)的asp文件

第二个参数为相对路径 也可以用更目录绝对路径(/...) 的html文件
飞鸟ASP生成HTM插件http://www.zhouhaihe.com/asp-to-htm/
Download ( 422 downloads)
8月19

时间提示函数

10:59ASP  From: Original

1.

<%dim n
select case hour(now)
case "6","7","8","9","10","11" n="上午"
case "12" n="中午"
case "13","14","15","16","17" n="下午"
case "18","19","20","21","22","23" n="晚上"
case "0","1","2","3","4","5" n="凌晨"
end select
response.write n&amp;"好"%>

2.

<% if time < #12:00:00# and time >= #00:00:00# then %>
<img src="Pic/biaoqing/em14.gif" width="20" height="20" border="3" alt="哈哈:">
<font color="#004442F">哈楼啊!大飞问候你:早上好啊----</font>
<% elseif time <= #17:00:00# and time>= # 12:00:00# then %>
<img src="Pic/biaoqing/em17.gif" width="20" height="20" border="3" alt="">
<font color="#0000FF">哎!!下午好啊!现在都什么时候了你还在啊?</font>
<% elseif time <=#23:00:00# and time>#17:00:00# then %>
<img src="pic/biaoqing/em27.gif" width="20" height="20" border="0" alt="">
<font color="#FF0099#">我要走了!吃饭,睡觉了!拜拜!</font>
<% else %>
<font size="5" color="#66FFFF#"> <img src="pic/biaoqing/em03.gif" width="20" height="20" border="0" alt="pic">我走了!你慢慢聊啊!~
</font>
<% end if%>

3. <html>
<body >
<font color=blue>
<% if time<#12:00:00# and time>=#00:00:00# then %>
上午好!
<% elseif time<#19:00:00# and time>=#12:00:00# then %>
下午好!
<% else %>
晚上好!
<% end if %>
</font>
</body>
</html>  
4.

<SCRIPT language=JavaScript>

<!--
document.write("<left><b><font color=blue size=-1> ")
day = new Date()
hr = day.getHours()
if (hr ==1)
document.write("凌晨一点了,休息吧!")
if (hr ==2)
document.write("该休息了!")
if (hr ==3)
document.write("夜深人静!只有你还敲击鼠标!?")
if (hr ==4)
document.write("四点过了,你明天不上班???")
if (hr ==5)
document.write("该去晨运了!!!")
if (hr ==6)
document.write("你知道吗,现在国内网速最快!")
if (hr ==7)
document.write("早上好!祝你过得快乐!")
if ((hr ==8) &amp;#124;&amp;#124; (hr == 9) &amp;#124;&amp;#124; (hr ==10))
document.write("上午好!祝你今天愉快!")
if (hr ==11)
document.write("十一点过了,快下班了吧?")
if (hr ==12)
document.write("十二点过了,还不下班?")
if ((hr==13) &amp;#124;&amp;#124; (hr==14))
document.write("你不睡午觉?")
if ((hr==15) &amp;#124;&amp;#124; (hr==16) &amp;#124;&amp;#124; (hr==17))
document.write("下午好!")
if ((hr==18) &amp;#124;&amp;#124; (hr==19))
document.write("吃晚饭了吧?")
if ((hr==20) &amp;#124;&amp;#124; (hr==21) &amp;#124;&amp;#124; (hr==22))
document.write("今晚又在这玩电脑了,没节目?")
if (hr==23)
document.write("真是越玩越精神,不打算睡了?")
if (hr==0)
document.write("凌晨了,还不睡?")
document.write("</font></b></left>")
//--->

</SCRIPT>

8月3
firefox是不错的调试工具,嘿嘿!
Quotation

Request 对象 错误 'ASP 0207 : 80004005'

不能使用 Request.Form

/news/adddata-fxs-2009.asp,行 45

调用 BinaryRead 之后,不能使用 Request.Form 集合。


修改为upload.forms后如下正常运行

<%
if request.QueryString("action")="add" then

dim startime,conn,connstr,db,rs_s,rs_s1
startime=timer()
db="../zhibianfz.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
conn.Open connstr

Dim Upload,successful,tempCls,image,smallImage
'===============================================================================
set Upload=new AnUpLoad    '创建类实例
Upload.SingleSize=200*1024                  '设置单个文件最大上传限制,按字节计;默认为不限制
Upload.MaxSize=200*1024                  '设置最大上传限制,按字节计;默认为不限制
Upload.Exe="rar|jpg|bmp|gif"                  '设置合法扩展名,以|分割,忽略大小写
Upload.GetData()            '获取并保存数据,必须调用本方法
'===============================================================================
if Upload.Err>0 then            '判断错误号,如果myupload.Err<=0表示正常
   response.write Upload.Description       '如果出现错误,获取错误描述
else
    savePath=server.MapPath("fxsphotos")             '图片保存路径
    if upload.Forms("photo")<>"" then
        set tempCls=upload.files("photo")
        if tempcls.SaveToFile(savePath,0) then image=tempCls.FileName
        set tempCls=nothing
    end if


set news=server.CreateObject("adodb.recordset")

news.Open"select * from fxs",conn,1,3
news.AddNew()
news("company")=Upload.forms("company")
news("danganhao")=Upload.forms("danganhao")
news("kehubianhao")=Upload.forms("kehubianhao")
news("tel")=Upload.forms("tel")
news("fax")=Upload.forms("fax")
news("mobile")=Upload.forms("mobile")
news("im")=Upload.forms("im")
news("website")=Upload.forms("website")
news("email")=Upload.forms("email")
news("zhekoulv")=Upload.forms("zhekoulv")
news("yewuyuan")=Upload.forms("yewuyuan")
news("time")=now()
news("address")=Upload.forms("address")
news("contact")=Upload.forms("contact")
news("beizhu")=Upload.forms("beizhu")
news("photo")="fxsphotos/" & image
news.Update()
response.write "<script language=javascript>alert('添加成功!');history.go(-1);</script>"
response.End
conn.close
set news=nothing
end if
end if
set Upload=nothing
%>

8月3
Quotation

提示由于将在索引,主关键字或关系中创建重复的值,请求对表的改变没有成功.改变该字段中的或包含重复数据的字段中的数据,删除索引或重新定义索引以允许重复的值并再试一次.

解决方法,将选择“数据类型”为“数字”改为“自动编号”并设置为“主键”故障解除!
当然你改数据类型的时候系统会提示,我赶时间就干脆把那列干掉再新家了,有没有在不更改当前数据的情况下解决问题,有时间再弄了!cry
看数据库,发生错误时的设置
Highslide JS

改回来以后
Highslide JS

这样就OK了
Pages: 1/2 First page 1 2 Next page Final page [ View by Articles | List ]