java保留两位小数
double c=3.154215;
java.text.DecimalFormat myformat=new java.text.DecimalFormat(”0.00″);
String str = myformat.format(c);
java小数点问题:
方式一:
四舍五入
double f = 111231.5585;
BigDecimal b = new BigDecimal(f);
double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
保留两位小数
方式二:
java.text.DecimalFormat df =new java.text.DecimalFormat(”#.00″);
df.format(你要格式化的数字);
例:new java.text.DecimalFormat(”#.00″).format(3.1415926)
#.00 表示两位小数 #.0000四位小数 以此类推…
方式三:
double d = 3.1415926;
String result = String .format(”%.2f”);
%.2f %. 表示 小数点前任意位数 2 表示两位小数 格式后的结果为f 表示浮点型。
javascript中对URL字符串编码的方法
javascript中存在几种对URL字符串进行编码的方法:escape(),encodeURI(),以及encodeURIComponent()。这几种编码所起的作用各不相同。
escape() 方法:
采用ISO Latin字符集对指定的字符串进行编码。所有的空格符、标点符号、特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编码的16进制数字)。比如,空格符对应的编码是%20。
不会被此方法编码的字符: @ * / +
encodeURI() 方法:
把URI字符串采用UTF-8编码格式转化成escape格式的字符串。
不会被此方法编码的字符:! @ # $& * ( ) = : / ; ? + ’
encodeURIComponent() 方法:
把 URI字符串采用UTF-8编码格式转化成escape格式的字符串。与encodeURI()相比,这个方法将对更多的字符进行编码,比如 / 等字符。所以如果字符串里面包含了URI的几个部分的话,不能用这个方法来进行编码,否则 / 字符被编码之后URL将显示错误。
不会被此方法编码的字符:! * ( ) ’
因 此,对于中文字符串来说,如果不希望把字符串编码格式转化成UTF-8格式的(比如原页面和目标页面的charset是一致的时候),只需要使用 escape。如果你的页面是GB2312或者其他的编码,而接受参数的页面是UTF-8编码的,就要采用encodeURI或者 encodeURIComponent。
另外,encodeURI/encodeURIComponent是在javascript1.5之后引进的,escape则在javascript1.0版本就有。
Js中escape(),encodeURI()和encodeURIComponent()方法比较
escape(), encodeURI()和encodeURIComponent()是在Javascript中用于编码字符串的三个常用的方法,而他们之间的异同却困扰 了很多的Javascript初学者,在这里对这三个方法详细地分析与比较一下。
escape() 方法
MSDN JScript Reference中如是说:
The escape method returns a string value (in Unicode format) that contains the contents of [the argument]. All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding, where xx is equivalent to the hexadecimal number representing the character. For example, a space is returned as “%20.”
译:escape方法以Unicode格式返回一个包含传入参数内容的string类型的值。 Escape方法会将传入参数中所有的空格、标点符号、重音字符以及其它任何非ASCII字符替换为%xx的编码形式,其中xx与其所表示的字符的16进 制数表示形式相同。如空格字符的16进制表示形式为0×20,则此时xx应为20,即escape(‘ ’) 返回“%20”。
Mozilla Developer Core Javascript Guide中如是说:
The escape and unescape functions let you encode and decode strings. The escape function returns the hexadecimal encoding of an argument in the ISO Latin character set. The unescape function returns the ASCII string for the specified hexadecimal encoding value.
译:escape和unescape方法能够帮助你编码和解码字符串。escape方法对于ISO Latin字符集中的字符组成的参数,返回其16进制编码。相对应的,unescape方法则能将16进制编码形式的参数转化成为其ASCII码形式。
encodeURI()方法
MSDN JScript Reference中如是说:
The encodeURI method returns an encoded URI. If you pass the result to decodeURI, the original string is returned. The encodeURI method does not encode the following characters: “:”, “/”, “;”, and “?”. Use encodeURIComponent to encode these characters.
译:encodeURI方法返回一个经过编码的URI。如果将encodeURI方法的编码结果传递给decodeURI方法作参数,则能得到原始 的未编码的字符串。需要注意到是encodeURI方法不编码如下字符”:”, “/”, “;”, and “?”。如果想要编码这些字符,请使用encodeURIComponent方法。
Mozilla Developer Core Javascript Guide中如是说:
Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.
译:通过将每个属于特定的字符集合的字符替换为一个、两个或者三个(为什么是“一个、两个或者三个”本人也没有搞懂,望高人赐教)使用UTF-8编 码来表示这个字符的escape序列来编码一个URI。如 ~!@#$%^&*(){}[]=:/,;?+”” 将被替换为 ~!@#$%25%5E&*()%7B%7D%5B%5D=:/,;?+”%22%5C
encodeURIComponent()方法
MSDN JScript Reference中如是说:
The encodeURIComponent method returns an encoded URI. If you pass the result to decodeURIComponent, the original string is returned. Because the encodeURIComponent method encodes all characters, be careful if the string represents a path such as /folder1/folder2/default.html. The slash characters will be encoded and will not be valid if sent as a request to a web server. Use the encodeURI method if the string contains more than a single URI component.
译:encodeURIComponent方法返回一个编码过的URI。如果将encodeURIComponent方法的编码结果传递给 encodeURIComponent方法作参数,则能得到原始的未编码的字符串。因为encodeURIComponent方法会编码所有的字符,所以 如果待编码的字符串是用来表示一个路径(如/dir1/dir2/index.htm)时,就一定要小心使用了。‘/’符号会被其编码之后,将不再是一个 有效的路径标识符,所以不能被web服务器正确地识别。当字符串包含一个单独的URI component(指?后面的请求参数)的时候,请使用此方法。
Mozilla Developer Core Javascript Guide中如是说:
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.
译:通过将每个属于特定的字符集合的字符替换为一个、两个或者三个(为什么是“一个、两个或者三个”本人也没有搞懂,望高人赐教)使用UTF-8编 码来表示这个字符的escape序列来编码一个URIComponent。
有什么区别?何时使用?
通过上面的介绍可以看出,MS的文档明显要比Mozilla详细、易懂一些,但是它们表达的都是一个意思。但是escape(), encodeURI()和 encodeURIComponent()有什么异同,它们分别适用于那种特定的情况呢?
escape方 法并不编码字符+。而我们知道,在用户提交的表单字段中,如果有空格,则会被转化为+字符,而服务器解析的时候则会认为+号代表空格。由于这个缺 陷,escape方法并不能正确地处理所有的非ASCII字符,你应当尽量避免使用escape方法,取而代之,你最好选择 encodeURIComponent()方法。
escape()不编码的字符:@*/+
相对于使用escape方法,使用encodeURI方法会显得更专业一些。当你需要编码一整个URI的时候,你可以使用此方法,因为URI中的合 法字符都不会被编码转换。需要注意到是字符’也是URI中的合法字符,所以也不会被编码转换。
encodeURI() 不编码的字符: ~!@#$&*()=:/,;?+”
encodeURIComponent方法在编码单个URIComponent(指请求参数)应当是最常用的。需要注意到是字符’也是URI中的合 法字符,所以也不会被编码转换。
encodeURIComponent()不编码的字符: ~!*()”
flash的attachMovie使用方法
先来看一些关于MovieClip.attachMovie的语法:
anyMovieClip.attachMovie(idName, newname, depth);
参数:
idName 要绑定的库中Movie的名字。这个名字就是元素的Linkage Properties对话框中输入的标识名。
newname 就是被绑定MC的实体名,必须是唯一的。
depth 一个整数值,用来指定MC所在的深度值。
说明:
方法;为库中的动画产生一个新的实体,并绑定指定的anyMovieClip中。使用 removeMovieClip 或者 unloadMovie 动作或者方法可以删除绑定的动画。
播放器:
Flash 5 或以后版本。
参考:
removeMovieClip
unloadMovie
MovieClip.removeMovieClip
MovieClip.unloadMovie
相信大家都用过attachMovie这个语句,可以方便的绑定库中带Linkage输出的元素, 在一些游戏以及交互程度比较高的网站中经常会用到。 那么这里就遇到一个问题,假如我在sub.fla库里面用linkage设定了几个元素, 然后想在main.fla里面attachMovie这几个元素,该如何处理尼?
第一种方法,main.fla使用 loadMovie(); 或 loadMovieNum();先导入 sub.swf, 然后导入完成后,再使用attachMovie来绑定元素。 但是这种方法,使用受到一个很大的限制,就是只能在 loadMovieNum()语句导入所在的层,或者loadMovie()语句导入所在的mc上面使用attachMovie, 比如:
loadMovieNum(”sub.swf”,1);
_level1.attachMovie(”cc”,”cc1″,5);
是有效的
loadMovieNum(”sub.swf”,1);
_level0.attachMovie(”cc”,”cc1″,5);
是无效的
同样:
loadMovie(”sub.swf”, “abc”);
_root.abc.attachMovie(”cc”, “cc2″, 50);
是有效的
loadMovie(”sub.swf”, “abc”);
_root.attachMovie(”cc”, “cc2″, 50);
是无效的
第二种方法,使用Export for runtime sharing的方式,方法如下:
在sub.fla中,设置好需要attach元素的 Linkage值,并选定 Export for ActionScript 以及 Export in first frame这两项
然后,在sub.fla中新建一个空的mc, 在库中设置这个空mc的linkage值为 ext ,选定 Export in first frame 以及 export for runtime sharing, URL这一项则填写为 sub.swf 如图:
在main.fla中,新建一个空的mc,在库中设置这个空mc的linkage值为 ext ,然后选定 Import for runtime sharing , URL一项填为 sub.swf
然后在main.fla中,再新建一个mc,从库中把刚才的ext这个空mc拖放到新建的这个mc中,然后把这个新mc任意设置一个linkage值,然后选定Export for ActionScript 以及 Export in first frame这两项。
做好以上的两步,就可以在main.fla里面任意attach sub.fla里面的可用元素了,比如:
attachMovie(”cc”,”cc”, 1);
attachMovie(”bar”,”bar”, 2);
第三种方法, 采用上面的第二种方法虽然已经很理想了,不过还是有一个限制,那就是必须编辑 sub.fla,加入 ext这个空mc, 那么有没有方法绕过去,可以不需要改动sub.fla,直接在main.fla里面做文章尼? 下面就介绍第三种实用方法:
假定我们现有一个tt.swf这个文件,里面库中设置了 linkage 为 a,b,c 的三个可用元素, 那么用下面的方法,可以不修改tt.fla,直接attach tt.swf里的这三个元素
我们打开主控文件mm.fla, 新建一个空mc,然后在库中设置linkage值为 a (或者b或者c,只要保持和tt.swf里面的某个linage值同名即可) ,然后选定 Import for runtime sharing , URL一项填为 tt.swf,
然后在mm.fla中,再新建一个mc,从库中把刚才的a这个空mc拖放到新建的这个mc中,然后把这个新mc任意设置一个linkage值,然后选定Export for ActionScript 以及 Export in first frame这两项。
然后就可以在mm.fla里面任意attach tt.fla里面的可用元素了,比如:
_root.attachMovie(”c”, “c”, 1);
_root.attachMovie(”a”, “a”, 11);
_root.attachMovie(”b”, “b”, 111);
ASP日期相关处理方法
FormatDateTime 函数
返回表达式,此表达式已被格式化为日期或时间。
FormatDateTime(Date[, NamedFormat])
参数
Date
必选项。要被格式化的日期表达式。
NamedFormat
可选项。指示所使用的日期/时间格式的数值,如果省略,则使用 vbGeneralDate。
设置
NamedFormat 参数可以有以下值:
常数 值 描述
vbGeneralDate 0 显示日期和/或时间。如果有日期部分,则将该部分显示为短日期格式。如果有时间部分,则将该部分显示为长时间格式。如果都存在,则显示所有部分。
vbLongDate 1 使用计算机区域设置中指定的长日期格式显示日期。
vbShortDate 2 使用计算机区域设置中指定的短日期格式显示日期。
vbLongTime 3 使用计算机区域设置中指定的时间格式显示时间。
vbShortTime 4 使用 24 小时格式 (hh:mm) 显示时间。
说明
下面例子利用 FormatDateTime 函数把表达式格式化为长日期型并且把它赋给 MyDateTime:
Function GetCurrentDate
‘FormatDateTime 把日期型格式化为长日期型。
GetCurrentDate = FormatDateTime(Date, 1)
End Function
ASP中怎样获取单选框的值
<html>
<head><title>sex</title></head>
<%
strsex=”"
if request(”radsex”)=”M” then
strsex=”帅哥”
elseif request(”radsex”)=”F” then
strsex=”美女”
end if
if request(”radedu”)=”1″ then edu=”初中”
if request(”radedu”)=”2″ then edu=”高中”
if request(”radedu”)=”3″ then edu=”大学”
if request(”radedu”)=”4″ then edu=”硕士”
response.write “这位” &strsex &”的学历是” &edu
%>
<form method=post action=”sex.asp”>
<fieldset>
<legend>性别</legend>
<input type=radio name=radsex value=”M” checked>男</br>
<input type=radio name=radsex value=”F”>女</br>
</fieldset>
<fieldset>
<legend>学历</legend>
<input type=radio name=radedu value=1 checked>初中</br>
<input type=radio name=radedu value=2>高中</br>
<input type=radio name=radedu value=3>大学</br>
<input type=radio name=radedu value=4>硕士</br>
</fieldset>
<p></p>
<input type=submit name=btnok value=确定>
</form>
</body>
</html>
ASP无组件上传后乱码问题
第一步:修改 连接数据库文件
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%>
<%
Option Explicit
Response.Buffer = True
Server.ScriptTimeOut = 90
Session.CodePage=936
%>
参考的是:
如果制作的网页脚本与WEB服务端的默认代码页不同,则必须指明代码页:
codepage=936 简体中文GBK
codepage=950 繁体中文BIG5
codepage=437 美国/加拿大英语
codepage=932 日文
codepage=949 韩文
codepage=866 俄文
codepage=65001 unicode UFT-8
第二步:把所有的
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
改成
<meta http-equiv=”Content-Type” content=”text/html; charset=GB2312″ />
再另存为ANSI
==========================================
GB2312转换为UTF-8编码的方法
第一步:
修改连接数据库文件
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”65001″%>
<%
Option Explicit
Response.Buffer=True
Session.CodePage=65001
Server.ScriptTimeOut = 90
%>
然后修改页面,将程序代码:
<meta http-equiv=”Content-Type” content=”text/html; charset=GB2312″ />
修改为:
程序代码:
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
第二步:
将所有ASP和JS文件,用记事本打开,然后另存为,编码本来是默认, 选择成UTF-8就可以了
第三步:
插入insert into content(a1,a2,a3) values(N’ “&a1&”‘,N’ “&a2&”‘)
asp获取浏览器类型及操作系统版本
Function SystemCheck()
useragent=Request.ServerVariables(”HTTP_USER_AGENT”)
‘转化为小写
useragent=Lcase(useragent)
‘Browser Check
dim btype,bname,bversion,idx,Os
btype=”"
if inStr(useragent,”icab”) then
bname=”iCab”
elseif inStr(useragent,”lynx”) then
bname=”Lynx”
elseif inStr(useragent,”links”) then
bname=”Links”
elseif inStr(useragent,”elinks”) then
bname=”ELinks”
elseif inStr(useragent,”jbrowser”) then
bname=”JBrowser”
elseif inStr(useragent,”konqueror”) then
bname=”Konqueror”
elseif inStr(useragent,”gecko”) then
bname=”Mozilla”
btype=btype &”[Gecko]”
if inStr(useragent,”aol”) then
bname=”AOL”
elseif inStr(useragent,”netscape”) then
bname=”Netscape”
elseif inStr(useragent,”firefox”) then
bname=”FireFox”
elseif inStr(useragent,”chimera”) then
bname=”Chimera”
elseif inStr(useragent,”camino”) then
bname=”Camino”
elseif inStr(useragent,”galeon”) then
bname=”Galeon”
elseif inStr(useragent,”k-meleon”) then
bname=”K-Meleon”
end if
elseif inStr(useragent,”bot”) or inStr(useragent,”crawl”) or inStr(useragent,”spider”) or inStr(useragent,”mediapartners”) or inStr(useragent,”slurp”) then
btype=btype &”[Bot/Crawler/Spider]”
if inStr(useragent,”grub”) then
bname=”Grub”
elseif inStr(useragent,”googlebot”) or inStr(useragent,”google”) then
bname=”GoogleBot”
elseif inStr(useragent,”baidu”) then
bname=”BaiduBot”
elseif inStr(useragent,”sogou”) then
bname=”SogouBot”
elseif inStr(useragent,”msnbot”) then
bname=”MSN Bot”
elseif inStr(useragent,”slurp”) then
bname=”Yahoo! Slurp”
end if
elseif inStr(useragent,”wget”) then
bname=”Wget”
elseif inStr(useragent,”ask jeeves”) or inStr(useragent,”teoma”) then
bname=”Ask Jeeves/Teoma”
elseif inStr(useragent,”msie”) then
btype=”[IE"
bversion=Mid(useragent,inStr(useragent,"msie")+5,3)
btype=btype & bversion &"]”
bname=”IE”
if inStr(useragent,”msn”) then
bname=”MSN”
elseif inStr(useragent,”aol”) then
bname=”AOL”
elseif inStr(useragent,”webtv”) then
bname=”WebTV”
elseif inStr(useragent,”myie2″) then
bname=”MyIE2″
elseif inStr(useragent,”maxthon”) then
bname=”Maxthon”
elseif inStr(useragent,”gosurf”) then
bname=”GoSurf”
elseif inStr(useragent,”netcaptor”) then
bname=”NetCaptor”
elseif inStr(useragent,”sleipnir”) then
bname=”Sleipnir”
elseif inStr(useragent,”avant browser”) then
bname=”AvantBrowser”
elseif inStr(useragent,”greenbrowser”) then
bname=”GreenBrowser”
elseif inStr(useragent,”slimbrowser”) then
bname=”SlimBrowser”
end if
elseif inStr(useragent,”opera”) then
bname=”Opera”
idx=inStr(useragent,”opera”)
bversion=mid(useragent,idx+6,idx+9)
bname=bname & bversion
elseif inStr(useragent,”applewebkit”) then
btype=”[AppleWebKit]”
if inStr(useragent,”omniweb”) then
bname=”OmniWeb”
elseif inStr(useragent,”safari”) then
bname=”Safari”
elseif inStr(useragent,”mozilla”) then
bname=”Mozilla”
end if
end if
‘Os Check
if inStr(useragent,”windows ce”) then
Os=”Windows ce”
elseif inStr(useragent,”windows 95″) then
Os=”Windows 95″
elseif inStr(useragent,”windows 98″) then
Os=”Windows 98″
elseif inStr(useragent,”windows 2000″) then
Os=”Windows 2000″
elseif inStr(useragent,”windows xp”) then
Os=”Windows XP”
elseif inStr(useragent,”windows nt 5.0″) then
Os=”Windows 2000″
elseif inStr(useragent,”windows nt 5.1″) then
Os=”Windows XP”
elseif inStr(useragent,”windows nt 5.2″) then
Os=”Windows 2003″
elseif inStr(useragent,”windows nt”) then
Os=”Windows NT”
elseif inStr(useragent,”win32″) then
Os=”Win32″
elseif inStr(useragent,”x11″) or inStr(useragent,”unix”) then
Os=”unix”
elseif inStr(useragent,”sunos”) or inStr(useragent,”sun os”) then
Os=”SUN OS”
elseif inStr(useragent,”powerpc”) or inStr(useragent,”ppc”) then
Os=”PowerPC”
elseif inStr(useragent,”macintosh”) then
Os=”Mac”
elseif inStr(useragent,”mac osx”) then
Os=”MacOSX”
elseif inStr(useragent,”freebsd”) then
Os=”FreeBSD”
elseif inStr(useragent,”linux”) then
Os=”Linux”
elseif inStr(useragent,”palmsource”) or inStr(useragent,”palmos”) then
Os=”PalmOS”
elseif inStr(useragent,”wap “) then
Os=”WAP”
end if
if bname=”" then bname=”unknow”
if Os=”" then Os=”unknow”
SystemCheck=bname & btype & “/” &Os
end Function
asp中修补upfile.asp上传漏洞
ASP文件相关的一些函数。有以下几个:
1. 得到文件扩展名
2. ASP上传文件漏洞检测
3. 格式化显示文件大小
4. asp检测上传图片是否为真实图片
5. 上传文件扩展名检测
6. 取得文件对应的图标
7. 下载文件等相关函数
程序代码:
<%
‘*******************************************************
‘作 用: 得到文件扩展名
‘函数名: GetFileExt(fileTrue)
‘参 数: sFileName 文件名
‘返回值: 返回文件扩展名
‘*******************************************************
function GetFileExt(sFileName)
GetFileExt = UCase(Mid(sFileName,InStrRev (sFileName, “.”)+1)) ‘下面有附
End function
‘*******************************************************
‘作 用: ASP上传漏洞 “″ 防范
‘函数名: TrueStr(fileTrue)
‘参 数: sFileName 文件名
‘返回值: 合法文件返回 True ,否则返回False
‘*******************************************************
function IsTrueFileName(sFileName)
dim str_len,pos
str_len=len(sFileName)
pos=Instr(sFileName,chr(0))
If pos=0 or pos=str_len then
IsTrueFileName = true
else
IsTrueFileName = false
End If
End function
‘*******************************************************
‘作 用: 检测上传的图片文件(jpeg,gif,bmp,png)是否真的为图片
‘函数名: TrueStr(fileTrue)
‘参 数: sFileName 文件名(此处文件名是文件夹的物理全路径)
‘返回值: 确实为图片文件则返回 True ,否则返回False
‘*******************************************************
function IsImgFile(sFileName)
const adTypeBinary=1
dim return
dim jpg(1):jpg(0)=CByte(&HFF):jpg(1)=CByte(&HD8)
dim bmp(1):bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
dim png(3):png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
dim gif(5):gif(0)=CByte(&H47):gif(1)=CByte(&H49):gif(2)=CByte(&H46):gif(3)=CByte(&H39):gif(4)=CByte(&H38):gif(5)=CByte(&H61)
on error resume next
return=false
dim fstream,fileExt,stamp,i
‘得到文件后缀并转化为小写
FileExt = LCase(GetFileExt(sFileName))
‘如果文件后缀为 jpg,jpeg,bmp,gif,png 中的任一种
‘则执行真实图片判断
If strInString(FileExt,”jpg|jpeg|bmp|gif|png”)=true then
Set fstream=Server.createobject(”ADODB.Stream”)
fstream.Open
fstream.Type=adTypeBinary
fstream.LoadFromFile sFileName
fstream.position=0
select case LCase(FileExt)
case “jpg”,”jpeg”
stamp=fstream.read(2)
for i=0 to 1
If ascB(MidB(stamp,i+1,1))=jpg(i) then return=true else return=false
next
case “gif”
stamp=fstream.read(6)
for i=0 to 5
If ascB(MidB(stamp,i+1,1))=gif(i) then return=true else return=false
next
case “png”
stamp=fstream.read(4)
for i=0 to 3
If ascB(MidB(stamp,i+1,1))=png(i) then return=true else return=false
next
case “bmp”
stamp=fstream.read(2)
for i=0 to 1
If ascB(MidB(stamp,i+1,1))=bmp(i) then return=true else return=false
next
End select
fstream.Close
Set fseteam=nothing
If err.number<>0 then return = false
else
return = true
End If
IsImgFile = return
End function
‘*******************************************************
‘作 用: 上传文件扩展名检测
‘函数名: CheckFileExt
‘参 数: sFileExt 上传文件夹的后缀
‘ strExt 允许或禁止上传文件夹的后缀,多个以”|”分隔
‘ blnAllow 是允许还是禁止上传 strExt 中指定的后缀
‘返回值: 合法文件返回 True ,否则返回False
‘*******************************************************
Function CheckFileExt(sFileExt,strExt,blnAllow)
dim arrExt,return
‘= 禁止上传的文件列表
’strExt = “EXE|JS|BAT|HTML|HTM|COM|ASP|ASA|DLL|PHP|JSP|CGI”
sFileExt = UCase(sFileExt)
strExt = UCase(strExt)
arrExt = split(strExt,”|”)
If blnAllow=true then ‘只允许上传指定的文件
return = false
for i=0 to UBound(arrExt)
If sFileExt=arrExt(i) then return=true
next
‘response.write “Ext: “&sFileExt & ” return: ” & return & “ ”
else ‘禁止上传指定的文件
return = true
for i=0 to UBound(arrExt)
If sFileExt=arrExt(i) then return=false
next
End If
CheckFileExt = return
End Function
‘*******************************************************
‘作 用: 格式化显示文件大小
‘FileSize: 文件大小
‘*******************************************************
Function FormatSize(FileSize)
If FileSize<1024 then FormatSize = FileSize & ” Byte”
If FileSize/1024 <1024 And FileSize/1024 > 1 then
FileSize = FileSize/1024
FormatSize=round(FileSize*100)/100 & ” KB”
Elseif FileSize/(1024*1024) > 1 Then
FileSize = FileSize/(1024*1024)
FormatSize = round(FileSize*100)/100 & ” MB”
End If
End function
‘*******************************************************
‘作 用: 取得文件对应的图标
‘函数名: FormatSize(FileSize)
‘参 数: FileName 文件名
‘返回值: 合法文件返回 True ,否则返回False
‘*******************************************************
Function GetFileIcon(FileName)
dim FileExt,Fso1
FileExt = GetFileExt(FileName)
ImgPath= strAdminRoot & “Style/images/file/” & FileExt & “.gif”
Set Fso1 = Server.CreateObject(”Scripting.FileSystemObject”)
If Fso1.fileExists(server.MapPath(ImgPath))=true then
GetFileIcon= “<img src=”"” & ImgPath & “”">”
else
GetFileIcon= “<img src=”"” & strAdminRoot & “Style/images/file/unknow.gif” & “”">”
End If
Set Fso1=nothing
End Function
‘*******************************************************
‘作用:下载文件。
‘函数名: DownFile(FileName)
‘ FileName
‘*******************************************************
Sub DownFile(FileName)
fname = server.MapPath(fname)
filename=split(fname,””)
Set objAdoStream=Server.createObject(”ADODB.Stream”)
objAdoStream.Type=1
objAdoStream.open()
objAdoStream.LoadFromFile(fname)
strchar=objAdoStream.Read()
fsize=objAdoStream.size
objAdoStream.Close()
Set objAdoStream=nothing
Response.AddHeader “content-type”,”application/x-msdownload”
response.AddHeader “Content-Disposition”,”attachment;filename=” & filename(ubound(filename))
Response.AddHeader “content-length”, fsize
Response.BinaryWrite(strchar)
Response.Flush()
End Sub
%>
——————————————————————————————————————————
附1:
Mid 函数
返回 Variant (String),其中包含字符串中指定数量的字符。
语法
Mid(string, start[, length])
start 必要参数。为 Long。string 中被取出部分的字符位置。如果 start 超过 string 的字符数,Mid 返回零长度字符串 (”")。
length 可选参数;为 Variant (Long)。要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到尾端的所有字符。
有可能是你的start变量值大于字符串长度,导致返回空字符串,或者是变量值为0,导致错误
附2:
InstrRev的用法
描述
返回某字符串在另一个字符串中出现的从结尾计起的位置。
语法
InstrRev(string1, string2[, start[, compare]])
InstrRev 函数的语法有以下参数:
参数 描述
string1 必选。接受搜索的字符串表达式。
string2 必选。被搜索的字符串表达式。
start 可选。数值表达式,用于设置每次搜索的开始位置。如果省略,则默认值为 -1,表示从最后一个字符的位置开始搜索。如果 start 包含 Null,则出现错误。
compare 可选。在计算子字符串时,指示要使用的比较类型的数值。如果省略,将执行二进制比较。有关数值,请参阅“设置”部分。
设置
compare 参数可以有以下值:
常数 Value 描述
vbBinaryCompare 0 执行二进制比较。
vbTextCompare 1 执行文本比较。
vbDatabaseCompare 2 执行基于包含在数据库(在此数据库中执行比较)中的信息的比较。
返回值
InStrRev 返回以下值:
如果 InStrRev 返回
string1 为零长度 0
string1 为 Null Null
string2 为零长度 start
string2 为 Null Null
string2 没有找到 0
在 string1 中找到 string2 找到匹配字符串的位置
start > Len(string2) 0
说明
请注意 InstrRev 函数的语法不同于 Instr 函数的语法。
ASP中页面另存为EXCEL的方法
<% Response.Buffer = TRUE
Response.AddHeader “Content-Disposition”,”attachment:filename=查询报表”&replace(now(),”:”, “-”)& “rxx “”.xls”
Response.contentType= “application/vnd.ms-excel”
%>
当页面存在数字时,导出EXCEL就变为科学记数法的形式,要使数字正常显示,请尝试下面办法。
“首先,我们了解一下excel从web页面上导出的原理。当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。下面就列出常用的一些格式:
1) 文本:vnd.ms-excel.numberformat:@
2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
3) 数字:vnd.ms-excel.numberformat:#,##0.00
4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
5) 百分比:vnd.ms-excel.numberformat: #0.00%
这些格式你也可以自定义,比如年月你可以定义为:yy-mm等等。那么知道了这些格式,怎么去把这些格式添加到cell中呢?很简单,我们只需要把样式添加到对应的标签对(即闭合标签)即可。如<td></td>,给标签对<td></td>添加样式,如下: <td style=”vnd.ms-excel.numberformat:@”>410522198402161833</td>
同样,我们也可以给<div></div>添加样式,也可以给<tr>< /tr>,<table></table>添加样式;当我们在父标签对和子标签对都添加样式时,数据会以哪一个样式呈现呢?经过测试,会以离数据最近的样式呈现.
- 默认分类(20)
- J2EE(25)
- Java(56)
- PHP(55)
- SEO(10)
- 网页设计(20)
- 网站建设(37)
- 数据库(7)
- JavaScript(17)
- JQuery(6)
- MySQL(20)
- SQL Server(6)
- Access(1)
- Oracle(6)
- office(6)
- Dreamweaver(4)
- Photoshop(12)
- Flash(9)
- Fireworks(13)
- CSS(14)
- HTML(4)
- .NET(7)
- ASP(2)
- DB2(1)
- Ajax(2)
- Linux(12)
- Struts(7)
- Hibernate(8)
- Spring(2)
- Jsp(22)
- Asp(8)
- C#(3)
- C++(1)
- 网络安全(5)
- 软件工程(7)
- XML(1)
- English(2)
- 计算机等级考试(2)
- 计算机病毒(4)
- 个人日志(76)
- 互联网(15)
- ActionScript(10)
- Android(3)
- 数据结构与算法(1)
- 游戏策略(3)
- 美文翻译(2)
- 编程开发(19)
- 计算机应用(4)
- 计算机(10)
- Unity3d(6)
- 其他(1)
- egret(1)