asp编程心得回放

asp编程心得回放

学好一门编程语言有两个条件是必不可少的,一是理论与实践结合,在实际例程去验证书本上的理论能加深你对理论的理解;二是学会总结,把学习、运用中的心得体会记下来,当成一种经验或者教训加以提炼并在日后的应用中加以改进,一定能提高你对这门编程语言的认识。以下是笔者在学习与运用ASP编程中的两点经验,希望能对大家有所帮助。

ASP页面内VBScript和JScript的交互

ASP具备管理不同语言脚本程序的能力,能够自动调用合适的脚本引擎以解释脚本代码和执行内置函数。ASP开发环境提供了两种脚本引擎,即VBScript(缺省)和

JScript。不过,开发者并没有被限制于只能使用这两种语言,只要能够提供合适的ActiveX脚本引擎就能使用任何脚本语言。

脚本语言的选择往往基于许多不同原因:它可能是开发者最为熟悉的语言,可能是对给定工程来说能够提供最多特色支持的,也有可能是最具效率的。不同的环境和要求使得我们在选择脚本语言时注重不同的因素,同时也使得我们在某些时候面临选定的脚本语言不能直接提供其它语言固有的函数这一问题,或某个脚本已经写成但用的却是另外一种脚本语言。

此时应该怎么办?是否需要用当前所用的脚本语言重写这些脚本?或者说,是否有可能在一种脚本语言中调用其它脚本语言的内置函数?本文要说明的就是在ASP应用中如何让VBScript脚本和JScript脚本交互以最大限度地获得两种脚本语言的特色支持。

一、VBScript和JScript的内置函数

在VBScript和JScript中,有大量的内置函数功能是相同或类似的。然而,在一种脚本语言中内置的函数并非总是在另外一种脚本语言中也有对应的函数。例如,VBScript提

供了许多用于操作字符串和格式化数据的函数,这些函数在JScript中并不存在。这些函数包括StrReverse()、Filter()以及FormatCurrency()等。在另一方面,JScript所提供的用于管理数组、字符串编码等的函数在VBScript中也没有定义,如join()、

reverse()、pow()、位操作、escape()和unescape()等。

那么,如果在JScript程序中需要一个VBscript函数该怎么办呢?

二、异种脚本的互相调用

如果需要在JScript脚本中调用一个VBScript中内置的函数,则应该写一个

VBScript用户定义函数(在这里调用VBScript内置函数),然后在JScript脚本中象调用公用JScript函数一样调用这个用户定义函数。

例如,如果要调用的VBSCript内置函数是FormatCurrency(),则可以声明如下自定义函数:

< SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">

Function FormatValue(Value)

FormatValue = FormatCurrency(Value)

End Function

< /SCRIPT>

接下来在JScript代码中就可以象普通JScript函数一样调用FormatValue()了。用类似的方法也可以实现VBScript代码调用JScript函数。

应用同样的规则,我们可以在任何脚本内调用任何用户定义函数。不过,从JScript脚本内调用一个不带参数的VBScript过程(Sub)时应略加注意,此时在JScript中应该象调用一个不带参数的JScript函数一样调用它,如用foo()调用VBScript Sub foo过程。

三、数据共享

在某些情形下混合运用VBScript和JScript函数是非常有用的,但在不同语言脚本之间共享数据也可能很有用。实现这种共享的方法很简单:不管使用的是什么语言,只要是在页面级声明的变量就可以任意引用。

对象的使用方法也相似,可以任意选用合适的语言读取、修改属性或调用对象的方法。当然给定对象的属性和方法是由创建该对象实例的语言所定义的。正如上例VBScript的过程调用,当从JScript中调用一个不带参数的VBScript对象的方法时,其调用方法也遵从JScript的调用规则,反之亦然。

四、数组管理

数组共享问题稍微复杂一点。虽然数组也象其它变量一样可以在不同语言脚本之间共享,但必须注意兼容方面的问题。

VBScript数组在JScript下可以用VBScript的符号引用,即用myArray(2)引用数组元素而不是JScript的数组元素引用符号myArray[2]。此外,还可以使用一个特殊的JScript对象——VBArray对象将VBScript数组转换为JScript数组。下面的代码从VBScript数组myVBArray创建JScript数组myJSArray:

var Temp = new VBArray(myVBArray)

var myJSArray

myJSArray = Temp.toArray()

上述代码首先创建一个临时的VBArray对象,然后使用它的toArray()方法将自己转换为JScript数组。此后就可以象普通JScript数组一样使用myJSArray,如

myJSArray[1]。但应当注意的是,toArray()方法将把一个多维的VBArray转换为一维的JScript数组。

从VBScript中引用JScript数组更为复杂。虽然在VBScript中我们可以直接访问JScript数组相关的方法和属性,但没有直接访问JScript数组的单个元素的方法。也就是说,我们可以在VBScript脚本中读取JScript数组的长度属性,如下所示:

x = myJSArray.length

但无法直接读取该数组的单个元素,下面的VBScript代码是不正确的:

x = myJSArray(3)

解决该问题的一个可行的方法是执行一个转换过程,如下面的代码所示,此处假定VBScript是缺省的脚本语言:

< %

Dim Temp

Dim myVBArray

Temp = myJSArray.join(", ")

myVBArray = Split(Temp, ", ")

%>

此处的JScript join()方法将数组myJSArray元素转换到一个以逗号为分割符的字符串,VBScript Split()函数将字符串转换为VBScript数组。注意这里我们是在VBScript环境下调用JScript的join方法。依照此例,我们可以通过自定义VBScript函数来模拟JScript的VBArray对象的toArray()方法以实现JScript数组到VBScript数组的转换。 用模板建立动态ASP页

对于模板,我想大家可能都有一些概念,在word中很多模板,设计好了大概的版面,你只要用你自己的话填充那些占位字符就好了。这儿的模板大概也就是这个意思,页面中相对稳定的部分固定下来,其他的部分根不同的情况在输入不同的内容。其实在

DreamWeaver中也有模板的功能,不过那个静态的,只能手动填充内容,而这儿讲的是动态的自动的内容填充。

首先,我先来解释一下为什么要用到模板文件。有时候,模板能够带给你对网页功能和布局更为完整的概念。当你看到Word的模板格式之后,就知道最后版面是个什么样子的了,在这儿也是如此。例如,你可以保留ASP语句,而使用不同的模板来建立不同的页面风格。

这样,你就不用为每种不同风格的网页分别来写不同的ASP页面了,这显然可以为我们节省很多时间和精力。而且,模板文件能够让你更容易的浏览页面代码,不用担心ASP和HTML的混杂搞的你头昏脑胀。你可以只用把注意力集中在HTML上,而完全不用去管ASP了。再有就是,摸板很简单,你绝对很快就能搞懂搞定。在这篇文章中,将会用到一个数据库——一个用的很广泛的雇员表。包括雇员ID,姓名,照片,以及工作摘要和照片的注脚。下面是这个Access数据库的结构:

文件名 - myDatabase.mdb

表名 - Employees

ID

自动计数(Autonumber)

FullName

文本 - 最多100个字符

PicURL

文本 - 最多255个字符

Duties

注释类型

PicCaption

文本 - 最多50个字符

一个很简单的数据库,是吧。当然你可以按要求来扩展它,那就是你自己的事了。我假设你已了解数据库的基本操作,这样我不用在这上面花太多的笔墨,其实这儿的代码都

是很简单的,只要你知道一些基本的东西,就能把它看懂。建立了数据库之后,我们可以开始建立模板文件了。这个文件是每个页面的骨架。我没有用到表格,那样有些麻烦,而我很懒,而且,也不用加入,标签,因为那是要加在ASP页面中的。所以到最后,它的样子就是这样了:

Full Name:

%name% < br>Description of duties:

%duties%

This picture was taken: %date%

Employee ID: %empID%

就是这样了!这就是一个简单的模板。把它存为template.tmp,在后面的ASP页面中将要引用到它。要注意的是:我们可以在模板中加入各种HTML标签,你完全可以在摸版中定义好网页的结构和样式,就像实际写一个网页一样,只是要把关键的地方标出来——注意到了那些%围着的东西了吗?那就是模板的精髓了。或许你已经注意到,那些%围着的是和数据库中的字段意义对应的。看看下面的ASP代码,是如何读入模板和数据库文件,把他们揉和在一起,然后输出我们想要的HTML页面。

这就是所有的代码了,很简单,不是吗?它所作的只是打开模板文件,按顺序读入每一行,然后用冲数据库中读入的实际的字段值来代替模版中那些%img%,%name%标记。而且,它还把在“Duties”字段内大段文本中的回车解释成HTML的回车 ,这样就不至于打乱整个的排版格式了。怎么样?轻松搞定吧。模板在某些应用上真的是可以发挥奇效,省时省力。理论上,你还可以修改这段代码,用FileSystemObject来读写文本,这样数据就不一定要存储在数据库中了。在一些应用中,比如即时的新闻发布,这样也许更为方便一些。

由弘一网童保存,尚未注册。注册

 

第二篇:asp编程经验谈

一、ASP开发10条经验总结

历时半年,我独自一人完成了一个局级单位的管理信息系统,共发布BETA版29次,正式版本3次。ASP+ORACLE环境,285个ASP文件,功能涉及数据录入、修改、模糊查询、自动统计、数据分析和报表,这个项目正在申报省级成果,现将我的10条经验总结如下,不对之处欢迎批评指正:

1. 不要再做ASP是否过时的讨论,重要的不是你是否使用先进的技术,而是你的设计思想是否先进;

2. 设计时要考虑项目的通用性,永远不要做没有推广价值的东西;

3. 程序设计要简洁,足够好的面向过程远远优于蹩脚的面向对象;

4. 理论是为实践服务的,所以不要被理论(尤其是设计模式)束缚;

5. 分工合理的情况下尽可能少的人员构成项目小组,通信的开销实在太大了;

6.没有不变的需求,要为你的程序留下足够多的拓展空间,同时要考虑在系统向其它平台移植时尽量减少工作量和难度的途径;

7. 千万不要忽视界面设计,很多情况下这成为对你项目评价的唯一标准;

8. 用正规文档记下你的变量使用情况,随着系统的增大,DEBUG的成本几乎成倍增长;

9. 能用机器生成的代码就不要去手写,最宝贵的就是时间;

10.选数据库还是要选ORACLE!

二、ASP开发准则

应用程序服务器被,或最终将被 Web 服务器所使用,它通常是运行 ASP 页面的 IIS 计算机。ASP 是您的对象的唯一客户机。它带来了专门的线程和安全考虑。

虽然许多使用 ASP 的 Web 站点根本就不用组件,但在这篇文章中假定 ASP 是 Internet 客户机和组件之间的桥梁。下面的 asp/server01242000.asp">ASP 组件准则(英文)提供

ASP 和组件之间的划分服务

ASP 最常用于在服务器上创建供客户机使用的 HTML 或 XML 文件,因此我们主要讨论这种使用方案。这就引出了一个常见的问题,如果 ASP 页面在服务器上,那么它们是否属于业务层的一部分呢?在组件世界中,答案通常是否。虽然 ASP 确实在服务器上运行,而且可能与应用程序服务器在同一个空间,但是这不能使它成为业务逻辑的一部分。

随着用户界面工具的发展或者随着启用更多的业务对业务方案,拥有这种明确的区别将获得巨大的回报。

话说到此,让我们来看一些最重要的业务层和表示层划分准则:

? 令 UI 代码与业务逻辑分离。这包括编写与 UI 耦合的代码,例如使用 ASP 内部组

件的 MTS 对象,让它与业务逻辑代码分离,如同在不同的 DLL 中。

? 将事务与 ASP 页面分离。事务 ASP 在某些情况下非常好,但是组件和多层应用程

序会改变这种情况。组件不应该依赖由客户机层来管理它们的事务和业务逻辑语义。 ? 将表示组件(使用请求和响应的组件)与 Web 服务器放在相同的机器和/或进程中。

如果将使用 ASP 内部组件对象的对象放在远程机器上,那么对内部组件的所有调用将以回调形式发生。调用 IIS 客户机的是 COM+ 服务器,它显著降低了性能并使安全配置复杂化。可以将这些调整对象放在标记为“库激活”的 COM+ 应用程序中。

ASP 存在于服务器上,因此 ASP 页面必须符合资源共享规则,并且记住可伸缩性。请看下面的详细内容:

?

? 在“会话”中,管理应尽量避免用户特定的状态。 保持 ASP 无状态,并在可能的情况下允许资源池。

操作方式

在评价某个代码段是否属于业务逻辑或者表示层时,请问一下自己,“如果我必须用按键式电话应用程序代替我的 ASP 页面,那么该代码是否还有用?”如果答案为“是”,那么可以尝试将它划分为业务逻辑代码或者用户界面帮助器代码。

如果改变了客户机后该代码不能用,或者如果它是构造用户界面的帮助器,则该代码属于表示服务层。它在 ASP 页面中,或在使用 ASP 内部组件的组件中。它不属于业务对象组件。

理解桌面与 ASP 客户机的区别

ASP 是组件的特殊客户机,不同于桌面上的传统单线程 Win32 应用程序。主要区别概括如下。

? 线程管理:ASP 是多线程客户机。这意味着可以有许多并发活动一起运行,也许在

同一时刻处理不同的 ASP 页面。这说明不能使对象伪称它是唯一的使用者来独占系统。这样做可能有意外的反应,例如,养成一个坏习惯:将对象存储在 ASP 会话或者应用程序变量中。

? 安全环境:ASP 是由 Web 站点中的 Internet Information Services 5.0 执行的,

有低、中、高三种隔离度。甚至这些 Web 站点可以有不同的安全设置、允许或拒绝匿名访问、验证客户等等。所有这些设置产生了大量的方案,即不同的用户帐户最终用的是您的对象。

? 轻松增长:这不是技术问题,而是 Web 应用程序所提供设施的副效应。传统上,为

桌面应用程序增加用户基,要求仔细计划好向已知数量客户机的转出。ASP 已经改变了该过程。在启动和运行后,ASP-Visual Basic 应用程序可以方便地打开,供当地的或世界范围的所有职员、所有业务伙伴和所有客户使用。可以用这种方式描述 — 拥有超链接的单个电子邮件可以使用户基成十倍地增长。您的应用程序为此作好准备了吗?唯一了解的方式是对 Web 站点进行强度测试,以获得实际性能的预期值。关于强度测试的详细信息,请参阅“应用程序生命周期”一节。

在 ASP 内应该如何使用 Visual Basic 对象?在页面范围内创建和取消您的对象。也就是说,尽可能使 ASP 页面无状态,只在暂时状态下依赖会话或应用程序变量。不要将对象存储在会话或应用程序变量中。这将 ASP 线程锁定到您的会话、取消所有可伸缩性的预

期值。也就是说,Web 服务器处理的用户数不会超过几十个。如果需要在会话或应用程序中存储内容,请使之成为数据而不是对象。

还有可以遵守的许多其他准则。我们建议您阅读 MSDN Voices 上 J. D. Meier 撰写的专栏“Servin' it Up”。该专栏包括了大量的技术、实践和技巧,有助于开发可扩展的、可靠的 ASP 和组件应用程序。

参考

asp#server">MSDN Voices: Servin' it Up Column(英文)

SeminarOnline:在 ASP 下使用自定义 COM 组件(英文)

asp">MSDN 杂志(英文)不要将引用存储在会话或应用程序中的 VB 对象中

所有 Visual Basic 6.0 组件都是“单元线程”的,就是说它们都运行在 STA 单元中。这意味着如果在线程中创建对象,那么对该对象的所有调用都必须用同一线程服务。许多线程(来自并发 Web 站点用户)使用 STA 对象的同一实例,会引起一连串的活动,有可能成为应用程序中的瓶颈。

此外,在会话范围内存储用 Server.CreateObject 创建的 STA 对象,可以有效地将执行线程联系到当前用户,从而将应用程序的最大并发用户数限制到默认的 20xN(N = 处理器数量)。

操作方式

如果您按照我们的建议使对象无状态,则不需要存储引用以供客户机复用,并在应用程序范围内存储它们。客户机将能够独立创建、使用和取消它们自己的对象。这就减少了保持会话特有对象的需要,原因是它们不保留会话特有的状态。

推荐的方式是使对象无状态,它在需要时访问数据库或其他存储区(例如 cookies 和 LDAP)。

如果需要使用会话或应用程序范围的数据,请将数据,而不是处理数据的对象,存储在此。您可以创建一个类,来封装对所需值的处理。

参考

asp">信息:不要在会话或应用程序中存储 STA 对象 (Q243543)(英文)

PRB:将 STA COM 组件存储在会话中,会将会话锁定在单线程中 (Q243815)(英文) 信息:ASP 下的组件线程模型概要 (Q243544)(英文)

学习 IIS 5.0 中的新内容

Internet Information Server 5.0 增加了许多新功能。这些改进均已写入 J.D. Meier 的 MSDN 文章中:asp/server02282000.asp">沿用 IIS 5.0 中的 ASP(英文)。下面是该文中最重要改进的概述。

?

?

?

?

?

?

?

? 改进的、出色的性能 Server.Transfer 和 Server.Execute 方法 集中式错误处理 改进的浏览器功能 改进的脚本引擎 正则表达式分析器 与 ADO 记录集 XML 功能的集成 新的安全性、缓冲、隔离和管理功能

三、Asp及Web开发中的常见问题

表格的折行处理.

<table style="TABLE-LAYOUT: fixed" width="200" border="0" cellspacing="0" cellpadding="7"

bgcolor="#f7f7f7">

<tr>

<td style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word"> dffadfdaqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsfdffadfdasfdffadfdasfdffadfdasfdffadfdasfdffadfdasfd

ffadfdasfdffadfdasfdffadfdasfdffadfdasf

</td>

</tr>

</table>

此处主要是用css样式进行控制在<table>标签中有个style="TABLE-LAYOUT: fixed",其说明如下

语法:

table-layout : auto | fixed

参数:

auto : 默认的自动算法。布局将基于各单元格的内容。表格在每一单元格读取计算之后才会显示出来。速度很慢

fixed : 固定布局的算法。在这算法中,水平布局是仅仅基于表格的宽度,表格边框的宽度,单元格间距,列的宽度,而和表格内容无关,此时在<td>标签中如果没有WORD-WRAP: break-word样式,表格中的内容将只能显示一部份,具体看表格的宽度了.word-wrap说明如下:

语法:

word-wrap : normal | break-word

参数:

normal : 允许内容顶开指定的容器边界

break-word : 内容将在边界内换行。如果需要,词内换行(word-break)也会发生

VBSCRIPT标记索引

基本运算

+ 数字加法及字符串连接

- 数字减法

* 数字乘法

/ 数字除法

Mod 求余数

\ 求商数

& 字符串连接

^ 次方

= 相等

<> 不相等

>= 大于或等于

> 大于

<= 小于或等于

< 小于

Not 非

And 且

Or 或

Xor 异或

循环及决策

if ....then 若...则...

if ...then...else 若...则...非 else if... 非若

select case... 群组选择条件 end select

for ... next 计数循环 while...wend 条件循环(一) do while...loop 条件循环(二) do...loop while 条件循环(三) do until...loop 条件循环(四) do...loop until 条件循环(五)

数学函数

Abs 绝对值

Sgn 正负号

Hex 转换成十六进制

Oct 转换成八进制

Sqr 平方根

Int 取整数

Fix 取整数

Round 取整数

Log 以e为底的对数

Sin 正弦函数

Cos 余弦函数

Tan 正切函数

字符串处理函数

Len 字符串长度

Mid 取部分字符串

Left 从字符串开头取部分字符串

Right 从字符串结尾取部分字符串

Lcase 转换成小写

Ucase 转换成大写

Trim 清除字符串开头及结尾的空格符

Ltrim 清除字符串开头空格符

Rtrim 清除字符串结尾空格符

Replace 替换字符串部分字符

Instr 判断是否包含于另一个字符串(从起始搜寻) InstrRev 判断是否包含于另一个字符串(从结尾搜寻) Space 任意字符数的空格符

String 任意字符数的任一字符

StrReverse 反转字符串

Split 以某字符分割字符串

数据类型转换函数

Cint 转换成整形

Cstr 转换成字符串

Clng 转换成常整数

Cbool 转换成布尔函数

Cdate 转换成日期函数

CSng 转换成单精度

CDbl 转换成双精度

日期时间函数

Date 现在日期

Time 现在时间 NOw 现在日期时间 DateAdd 增加日期 DateDiff 两日期差 DateSerial 日期设定 DateValue 日期设定 Year 现在年份 Month 现在月份 Day 现在天

Hour 现在时刻 Minute 现在分钟 Second 现在秒钟

Timer 午夜距现在秒数 TimeSerial 时间设定 TimeValue 时间所属部分 WeekDay 星期名称 MonthName 月份名称

其它函数

Array 产生数组 Asc 字符ASCII码 Chr ASCII码字符 Filter 过滤数组 InputBox 输入窗口 Join 合并数组中的元素 MsgBox 信息窗口 Lbound 数组下界 Ubound 数组上界

指令

Const 设定常数

Dim 定义变量或者数组

Erase 清除数组

ReDim 重新声明数组

Randomize 起始随机数

Rnd 取得随机数

ASP对象

Session对象

IsEmpty 测试Session变量是否存在 TimeOut 设定Session变量生存周期 Abandon 强制清除Session变量

Application对象

IsEmpty 测试Application变量是否存在 Lock 锁定Application变量

Unlock 解除Lock指令的锁定

Cookies对象

Expires 设定Cookies变量的生存周期

Connection对象

Open 打开与数据库的连接

Execute 打开Recordset对象 Close 关闭Connection对象

Recordset对象

movefirst 将记录指针移至第一条

movelast 将记录指针移至最后一条

movenext 将记录指针移至下一条

moveprevious 将记录指针移至上一条

bof 测试是否为recordset的起始

eof 测试是否为recordset的结束

open 打开Recoreset对象

close 关闭recordset对象

fields 读取数据的子对象

fileds.count 字段个数

pagesize 每页记录条数

absolutepage 设定为某页

pagecount 总页数

Absoluteposition 直接跳至某条记录

MicrosoftVBscript运行时错误列表(10进制表示)

error # 5 无效的过程调用或参数

error # 5 无效的过程调用或参数

error # 6 溢出

error # 7 内存不够

error # 9 下标越界

error # 10 该数组为定长的或临时被锁定 error # 11 被零除

error # 13 类型不匹配

error # 14 字符串空间不够

error # 17 不能执行所需的操作

error # 28 堆栈溢出

error # 35 未定义过程或函数

error # 48 加载 DLL 时出错

error # 51 内部错误

error # 52 错误的文件名或号码

error # 53 文件未找到

error # 54 错误的文件模式

error # 55 文件已经打开

error # 57 设备 I/O 错误

error # 58 文件已存在

error # 61 磁盘已满

error # 62 输入超出了文件尾

error # 67 文件过多

error # 68 设备不可用

error # 70 没有权限

error # 71 磁盘没有准备好

error # 74 重命名时不能带有其他驱动器符号 error # 75 路径/文件访问错误

error # 76 路径未找到

error # 91 对象变量未设置

error # 92 For 循环未初始化

error # 94 无效使用 Null

error # 322 不能创建必要的临时文件

error # 424 缺少对象

error # 429 ActiveX 部件不能创建对象

error # 430 类不支持 Automation 操作

error # 432 Automation 操作中文件名或类名未找到 error # 438 对象不支持此属性或方法

error # 440 Automation 操作错误

error # 445 对象不支持此操作

error # 446 对象不支持已命名参数

error # 447 对象不支持当前区域设置选项

error # 448 未找到已命名参数

error # 449 参数是必选项

error # 450 错误的参数个数或无效的参数属性值

error # 451 对象不是一个集合

error # 453 未找到指定的 DLL 函数

error # 455 代码资源锁定错误

error # 457 此键已与该集合的一个元素关联

error # 458 变量使用了一个 VBScript 中不支持的 Automation 类型 error # 462 远程服务器不存在或不可用

error # 481 无效图片

error # 500 变量未定义

error # 501 非法赋值

error # 502 对象不能安全用 Script 编程

error # 503 对象不能安全初始化

error # 504 对象不能安全创建

error # 505 无效的或无资格的引用

error # 506 类没有被定义

error # 507 出现一个意外错误

error # 1001 内存不够

error # 1002 语法错误

error # 1003 缺少 ':'

error # 1005 缺少 '('

error # 1006 缺少 ')'

error # 1007 缺少 ']'

error # 1010 缺少标识符

error # 1011 缺少 '='

error # 1012 缺少 'If'

error # 1013 缺少 'To'

error # 1014 缺少 'End'

error # 1015 缺少 'Function'

error # 1016 缺少 'Sub'

error # 1017 缺少 'Then'

error # 1018 缺少 'Wend'

error # 1019 缺少 'Loop'

error # 1020 缺少 'Next'

error # 1021 缺少 'Case'

error # 1022 缺少 'Select'

error # 1023 缺少表达式

error # 1024 缺少语句

error # 1025 语句未结束

error # 1026 缺少整型常数

error # 1027 缺少 'While' 或 'Until'

error # 1028 缺少 'While' 和 'Until'或语句未结束 error # 1029 缺少 'With'

error # 1030 标识符过长

error # 1031 无效数字

error # 1032 无效字符

error # 1033 未结束的字符串常量

error # 1034 注释未结束

error # 1037 无效使用 'Me' 关键字

error # 1038 'loop' 语句缺少 'do'

error # 1039 无效的 'exit' 语句

error # 1040 循环控制变量 'for' 无效

error # 1041 名称重定义

error # 1042 必须是行中的第一个语句

error # 1043 不能为 non-ByVal 参数赋值

error # 1044 调用子程序时不能使用括号

error # 1045 缺少文字常数

error # 1046 缺少 'In'

error # 1047 缺少 'Class'

error # 1048 必须在一个类的内部定义

error # 1049 在属性声明中缺少 Let , Set 或 Get

error # 1050 缺少 'Property'

error # 1051 在所有属性的规范中,变量的数目必须一致

error # 1052 在一个类中不允许有多个缺省的属性/方法

error # 1053 类的初始化或终止程序没有变量

error # 1054 属性的 set 或 let 必须至少有一个变量

error # 1055 错误的 'Next'

error # 1056 'Default' 只能在 'Property' , 'Function' 或 'Sub' 中指定 error # 1057 指定 'Default' 时必须同时指定 'Public'

error # 1058 只能在 Property Get 中指定 'Default'

error # 4096 Microsoft VBScript 编译器错误

error # 4097 Microsoft VBScript 运行时错误

error # 5016 缺少正则表达式对象

error # 5017 正则表达式语法错误

error # 5018 错误的数量词

error # 5019 正则表达式中缺少 ']'

error # 5020 正则表达式中缺少 ')'

error # 5021 字符集越界

树形菜单:

<SCRIPT language="JavaScript"> var lastObj

function expandIt(obj)

{

if(lastObj != null)

{

if(obj == lastObj)

{

if(obj.style.display == "none") {

obj.style.display = "";

}

else

{

obj.style.display = "none" }

}

else

{

lastObj.style.display = "none"; obj.style.display = "";

}

}

else

{

obj.style.display = "";

}

lastObj = obj

}

</SCRIPT>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<%

dim id

id = request("id")

dim strsql,rs

strsql="select * from p_type where slanguage=1 and typelevel=1 order by typename"

set rs=fgetrslist(strsql)

do while not rs.eof

%>

<tr>

<td height="25" class="LEFTLINKS"><img width="30" height="0" align="absmiddle" /><b><%if

rs("isleaf")=0 then%><a href="#" onClick="javascript:expandIt(kb<%=rs("id")%>);return false"><%else%><a href="<%=request.ServerVariables("SCRIPT_NAME")%>?idtree=<%=rs("idtree")%>" ><%end if%><%=server.HTMLEncode(right((rs("typename")&""),len(rs("typename")&"")-2))%></a></b></td> </tr>

<%

IF clng(id)=clng(rs("id")) then

%>

<tr id="kb<%=rs("id")%>">

<%

else

%>

<tr id="kb<%=rs("id")%>" style="display:none;">

<%

end if

%>

<td>

<table>

<%

dim rs1

strsql="select * from p_type where parentid="&rs("id")&" and slanguage=1 order by typename"

set rs1=fgetrslist(strsql)

do while not rs1.eof

%>

<tr><td height="20" class="LEFTLINKS">

<img width="40" height="0" align="absmiddle" /><a href="<

%=request.ServerVariables("SCRIPT_NAME")%>?idtree=<%=rs1("idtree")%>&id=<%=rs("id")%>" ><%=server.HTMLEncode(right((rs1("typename")&""),len(rs1("typename")&"")-2))%></a></td></tr> <%

rs1.movenext

loop

rs1.close

set rs1=nothing

%>

</table>

</td>

</tr>

<%

rs.movenext

loop

rs.close

set rs=nothing

%>

</table>

四、ASP文件中的安全问题

ASP中可能有哪些安全问题?

ASP具有简单、易用、多功能,可扩充性等强大功能,但也存在一些问题。譬如,如果使用ASP的话,可能会导致网络的安全性大大降低了!下面为大家举一个例子,请按照下面的步骤:

(1)从http:///xuankong/dll.zip下载这个文件,解压缩后把其中的test.dll文件拷贝到c:\windows\system(如果你使用的是NT的话,请拷贝到相应的目录中);

(2)接下来打开"开始/运行"菜单输入"regsvr32 test.dll"命令;

(3)拷贝解压后的文件包中的那个index.asp到你的服务器目录(如果你使用的是PWS调试可以拷贝到"c:\inetpub\wwwroot",NT请拷贝到相应的目录);

(4)换一台机器用IE浏览index.asp文件看一看(你看到的是出错代码,但是实际上程序已经运行了),你再返回你的机器看一看c:\下面是不是多了一个文件?一个名为

xuankong.dat的文件(其实如果我愿意,你的c:\autoexec.bat文件页可以被我打开并写进去一些像"format c:/q/u"等命令,那么等你下次重新启动的时候,结果就不言自明了)。

ASP页面的安全问题是如何产生的?

下面我们来看一下到底是怎么回事,你刚才拷贝的那些dll文件其实是我使用Visul Basic5开发的一个主件,这个文件是通过以下步骤产生的:

(1)打开VB5新建一个"ActiveX.dll"文件,吧下面的代码输入进去:

Private Declare Function ExitWindowsEx Lib "user32"_(ByVal uFlags As

Long,ByVal dwReserved As Long)_As LongSub Xuankong ( ) "请不要加上"private"a$ = InputBox ("请输入你的姓名,如果你输入的是"xuankong""+Chr(13)+Chr(10)+"则会在你的系统中生成一个"xuankong"文件"+Chr(10)+Chr(13)+"否则你的机器可能会重起","请输入","xuankong")If a$ = "xuankong" ThenOpen "c:\xuankong.dat" For Append As #Write#1,"我的朋友,这是一个asp主件测试程序"#Write#1,"hello world!this is a test"#Write#1,"如果你看到这个文件测试就成功!"elseExitWindowsEx&H43,0使用API函数重新启动机器End ifClose #1End sub

(2)把工程名改为dll,类模块改为test,然后把这个工程生成dll文件到

c:\windows\system目录下面。

(3)新建一个index.asp文件下面的代码输入进去:

<html> </html>

(4)拷贝index.asp到你的服务器内,按照上面的方法调试!

总结:

上面所说的是ASP主件的安全问题!另外如果有些作者再写ASP主件的时候不小心留下系统bug!那就更加不容易发现了!也可能会带来意想不到的问题。

五、关于如何保障Winnt +asp +sql web站点的安全经验

以下是我的一些经验,希望对你有用,但你要知道,绝对的安全是没有的。这才是一个网管存在的理由。所以。未雨绸缪是件好事。但亡羊补牢也不是下策。 请看我的经验:

1。多看看ms的安全公告,这是首选。订阅安全技术杂志。(MS免费的!)如果是正版的nt,则会有最新的安全E-mail。保证及时更新。

2。多大补丁,一定要注意顺序,如果安装了系统软件,则还要重补。(如后面加上了smtp服务,则还要重补sp1等等,否则可能导致旧文件不会被覆盖)。

3。提高安全策略,也可以用微软的安全模板。有一些很好的自动模板。可以根据需要自动加上。

4。加大审核力度,审核权限比较大的操作。

5。密码按时更改。必须符合策略。

6。常上一些安全论坛。如:绿盟科技,妖狐站点。

7。账号的级别一定要多分一些,如果可一实现功能,就不要给更大权限。

8。去掉多余的服务。如:(ftp,smtp,nntp,telnet)多余的脚本,例子。如IIS中好多的脚本库,都可以不要。

9。去掉一些危险的命令。不要共享c盘。

10。常看看日志,事件。

11。不要安装html的远端管理。

12。最好安装一些黑客工具,模拟攻击。看看是否出了问题。

13。安装端口扫描工具。看看是否有些不用的开放端口。

14。安装一些防止窃听的工具,去除一些隐藏在端口的sniffer,防止密码数据被截获。

15。远程管理时最好调试端管理。密码加密策略高一些。防止被截获。

16。用注册表修改掉某些选项。如自动显示最后一个登录着的姓名。

17。改掉administrator的缺省姓名。这样可以多一级保护!

18。密码策略

19。密码的安全策略。多少位的密码是安全的。这个很怪。按照ms的加密算法。只有14位以上的密码是可能安全的。但实际上很少有人能记住那么多位的密码。但14位一下。7位密码比较安全。(很怪吧。)微软工程师说有时7位比10位还要保险。呵呵,具体原因说起来比较复杂。我是给我老弟讲课的。省略吧。

20。建议密码有字母。数字。大小写组成。最好加上一些如!·#¥%()等的字符。也很难被猜到。

21。用户名改掉缺省的admini.....后,可以建一个14位长的管理员名。可以全部用字母。这样就加大了一级保护。

22。加大策略。防止用枚举法猜出账号名。

23。加入防止5次登录失败后,自动锁定账号20分中。防止暴力法突破。

24。建立分类的密码策略。不要用一些内置账号。如“sa”。

25。将sa的密码加大。最好不要常用他。建一个另外的管理员账号。然后对每一个自建的数据库都建一个分类账号。asp中最好用他来连接。这样就可以保障其他数据库的安全。

26。去掉一些权限。不允许普通用户用比较危险的存储过程。

27。不允许除管理员外的账号远程连接。或是加上命名管道。

27。asp如果能用dsn,就不要用连接字符串。并采取包含文件的模式包含进来。

六、

介绍 Web程序中网页间数据传递方法小结

我们总是会遇到这样的情况,需要将数值从一个网页传递到另一个网页。在这篇文章中,向你展示了几种从一个网页向另一个网页传递数值的几种方法。在此例子中,创建的网页由一个文本控件和几个按钮控件组成。在文本框中输入的数据通过被标识在按钮控件中的不同方法从一个网页传递到另一个网页。

Response.Redirect

让我们首先看一看如何使用Response.Redirect方法传递数据。这是它们之中最简单的方法。在文本框中输入一些数据,并且当你输入完成数据后,按下“Respose.Redirect”按钮。我们会得到一个提示,有时我们想在catch程序中传递另一个网页,意味着捕捉到例外程序并且向另一个网页传递。如果你试图这样做,它会给你一个System.Threading例外程序。因为你想遗留下一个线程向另一个网页传递数据,所以这个例外程序就会被抛出。

Response.Redirect("WebForm5.aspx",false);

这个语句告诉编译器定位到“WebForm5.aspx”,这里的“false”意味着在当前网页不能结束你正在做的事情。应该看一看线程发布命令的System.Threading类。在下面,看一看按钮事件的C#代码。“txtName”文本控件的名字,文本框的内的值传递到一个叫做“WebForm5.aspx”的网页。在“?”之后的“Name”符号只是一个临时的响应变量,这个变量保持着文本的数值。

private void Button1_Click(object sender, System.EventArgs e)

{

// Value sent using HttpResponse

Response.Redirect("WebForm5.aspx?Name="+txtName.Text);

}

好的,到这种观点为止,你使用Response发送了数值。刚刚,在此我收集到了这些数值,所以在“WebForm5.aspx”page_Load事件中,写入这些代码。首先,我们检查到输入的值不为null。如果不是这样,我们只是简单地在网页上使用Label控件显示数值。注意:如果你使用Response.Redirect方法来传递这些数值,所有这些数值在浏览器的URL中都是不可见的。你绝不能使用Response.Redirect来传递信用证号码和机密信息。

if (Request.QueryString["Name"]!= null)

Label3.Text = Request.QueryString["Name"];

Cookies

接下来使用Cookies。Cookies在服务器端创建,但是客户端省略。在此 “Cookies” 按钮的click事件中,写入以下代码:

HttpCookie cName = new HttpCookie("Name");

cName.Value = txtName.Text;

Response.Cookies.Add(cName);

Response.Redirect("WebForm5.aspx");

首先,创建一个cookie命名为“cName”。既然一个cookie实例可以拥有许多数值,告诉编译器这个cookie持有“Name”数值。我们将它赋值给TextBox并且最结后将它加入Response流,再使用Response.Redirect方法传递给其它网页。

让我们看一看如何得到被另一个网页传递的cookie数值。

if (Request.Cookies["Name"] != null )

Label3.Text = Request.Cookies["Name"].Value;

如你所看到的,象我们以前做一的一样正是使用同一种方法,刚刚我们在

Request.QueryString之内,使用了Request.Cookies。记注一些浏览器不接收cookies。

用文本+ASP打造新闻发布系统

//图片上传

〈SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT〉

Function GetUpload(FormData)

Dim DataStart,DivStr,DivLen,DataSize,FormFieldData

'分隔标志串(+CRLF)

DivStr = LeftB(FormData,InStrB(FormData,str2bin(VbCrLf)) + 1)

'分隔标志串长度

DivLen = LenB(DivStr)

PosOpenBoundary = InStrB(FormData,DivStr)

PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)

Set Fields = CreateObject("Scripting.Dictionary")

While PosOpenBoundary 〉 0 And PosCloseBoundary 〉 0

'name起始位置(name="xxxxx"),加6是因为[name="]长度为6

FieldNameStart = InStrB(PosOpenBoundary,FormData,str2bin("name=")) + 6

FieldNameSize = InStrB(FieldNameStart,FormData,ChrB(34)) - FieldNameStart '(")的ASC值=34 FormFieldName = bin2str(MidB(FormData,FieldNameStart,FieldNameSize))

'filename起始位置(filename="xxxxx")

FieldFileNameStart = InStrB(PosOpenBoundary,FormData,str2bin("filename=")) + 10

If FieldFileNameStart 〈 PosCloseBoundary And FieldFileNameStart 〉 PosopenBoundary Then FieldFileNameSize = InStrB(FieldFileNameStart,FormData,ChrB(34)) - FieldFileNameStart '(")的ASC值=34 FormFileName = bin2str(MidB(FormData,FieldFileNameStart,FieldFileNameSize)) Else

FormFileName = ""

End If

'Content-Type起始位置(Content-Type: xxxxx)

FieldFileCTStart = InStrB(PosOpenBoundary,FormData,str2bin("Content-Type:")) + 14 If FieldFileCTStart 〈 PosCloseBoundary And FieldFileCTStart 〉 PosOpenBoundary Then FieldFileCTSize = InStrB(FieldFileCTStart,FormData,str2bin(VbCrLf & VbCrLf)) - FieldFileCTStart FormFileCT = bin2str(MidB(FormData,FieldFileCTStart,FieldFileCTSize))

Else

FormFileCT = ""

End If

'数据起始位置:2个CRLF开始

DataStart = InStrB(PosOpenBoundary,FormData,str2bin(VbCrLf & VbCrLf)) + 4

If FormFileName 〈〉 "" Then

'数据长度,减1是因为数据文件的存取字节数问题(可能是AppendChunk方法的问题): '由于字节数为奇数的图象存到数据库时会去掉最后一个字符导致图象不能正确显示, '字节数为偶数的数据文件就不会出现这个问题,因此必须保持字节数为偶数。

DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 1

FormFieldData = MidB(FormData,DataStart,DataSize)

Else

'数据长度,减2是因为分隔标志串前有一个CRLF

DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 2

FormFieldData = bin2str(MidB(FormData,DataStart,DataSize))

End If

'建立一个Dictionary集存储Form中各个Field的相关数据 Set Field = CreateUploadField()

Field.Name = FormFieldName

Field.FilePath = FormFileName

Field.FileName = GetFileName(FormFileName)

Field.ContentType = FormFileCT

Field.Length = LenB(FormFieldData)

Field.Value = FormFieldData

Fields.Add FormFieldName, Field

PosOpenBoundary = PosCloseBoundary

PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)

Wend

Set GetUpload = Fields

End Function

'把二进制字符串转换成普通字符串函数

Function bin2str(binstr)

Dim varlen,clow,ccc,skipflag

'中文字符Skip标志

skipflag=0

ccc = ""

If Not IsNull(binstr) Then

varlen=LenB(binstr)

For i=1 To varlen

If skipflag=0 Then

clow = MidB(binstr,i,1)

'判断是否中文的字符

If AscB(clow) 〉 127 Then

'AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转 ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))

skipflag=1

Else

ccc = ccc & Chr(AscB(clow))

End If

Else

skipflag=0

End If

Next

End If

bin2str = ccc

End Function

'把普通字符串转成二进制字符串函数

Function str2bin(varstr)

str2bin=""

For i=1 To Len(varstr)

varchar=mid(varstr,i,1)

varasc = Asc(varchar)

' asc对中文字符求出来的值可能为负数,

' 加上65536就可求出它的无符号数值

' -1在机器内是用补码表示的0xffff,

' 其无符号值为65535,65535=-1+65536

' 其他负数依次类推。

If varasc〈0 Then

varasc = varasc + 65535

End If

'对中文的处理:把双字节低位和高位分开

If varasc〉255 Then

varlow = Left(Hex(Asc(varchar)),2)

varhigh = right(Hex(Asc(varchar)),2)

str2bin = str2bin & chrB("&H" & varlow) & chrB("&H" & varhigh) Else

str2bin = str2bin & chrB(AscB(varchar))

End If

Next

End Function

'取得文件名(去掉Path)

Function GetFileName(FullPath)

If FullPath 〈〉 "" Then

FullPath = StrReverse(FullPath)

FullPath = Left(FullPath, InStr(1, FullPath, "\") - 1)

GetFileName = StrReverse(FullPath)

Else

GetFileName = ""

End If

End Function

〈/SCRIPT〉

〈SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT〉 function CreateUploadField(){ return new uf_Init() }

function uf_Init(){

this.Name = null

this.FileName = null

this.FilePath = null

this.ContentType = null

this.Value = null

this.Length = null

}

〈/SCRIPT〉

//新闻添加

〈!--#include file="news_session.asp"--〉

〈html〉

〈head〉

〈meta http-equiv="Content-Language" content="zh-cn"〉

〈meta http-equiv="Content-Type" content="text/html; charset=gb2312"〉

〈style type="text/css"〉

.buttonface {

BACKGROUND-COLOR: #0079F2; BORDER-BOTTOM: #333333 1px outset; BORDER-LEFT: #333333 1px outset; BORDER-RIGHT: #ffffff 1px outset; BORDER-TOP: #ffffff 1px outset; COLOR: #ffffff; FONT-SIZE: 9pta { color: #000000; text-decoration: none}

〈/style〉

〈SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript〉

〈!--

function client_onblur(ii) {

server=eval("form1.server"+ii)

if(server.value==""){

client=eval("form1.client"+ii)

clientvalue=client.value+""

varlen=clientvalue.length

a=clientvalue.lastIndexOf('\\')

clientvalue=clientvalue.substring(a+1)

//alert(clientvalue);

server.value=clientvalue

}

}

function form1_onsubmit() {

for(i=1;i〈1;i++){

client=eval("form1.client"+i)

server=eval("form1.server"+i)

if(client.value!="" && server.value==""){alert("上传后的文件名不能空!");server.focus();return false} }

}

//--〉

〈/SCRIPT〉

〈title〉新闻发布系统〈/title〉

〈/head〉

〈body bgcolor=#EDF0F5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0〉

〈form method="POST" action="news_input.asp" name="form1" enctype="multipart/form-data"

LANGUAGE=javascript onsubmit="return form1_onsubmit()"〉

〈div align="left"〉

〈table border="1" width="754" height="404"〉

〈tr align="center"〉

〈td width="754" height="28" colspan="3" style="font-size:11pt"〉〈strong〉新闻发布系统后台管理--新闻添加〈/strong〉〈/td〉

〈/tr〉

〈tr〉

〈td width="121" height="16" align="center" style="font-size:9pt"〉新闻标题〈/td〉

〈td width="617" height="16" colspan="2"〉

〈input type="text" name="news_title" size="87"〉〈/td〉

〈/tr〉

〈tr〉

〈td width="121" height="165" align="center" style="font-size:9pt"〉新闻内容〈/td〉

〈td width="617" height="165" colspan="2"〉〈textarea rows="11" name="news_content" cols="85"〉〈/textarea〉〈/td〉

〈/tr〉

〈tr〉

〈td width="121" height="21" align="center" style="font-size:9pt"〉新闻来源〈/td〉

〈td width="617" height="21" colspan="2"〉

〈input type="text" name="news_src" size="87"〉〈/td〉

〈/tr〉

〈tr〉

〈td width="121" height="20" align="center" style="font-size:9pt" 〉图片上传〈/td〉

〈td width="617" height="20" colspan="2"〉

〈input type="file" name="client1" size="20" readonly LANGUAGE=javascript onblur="return

client_onblur(1)" 〉

〈span style="font-size:9pt"〉〈/span〉 〈INPUT type="hidden" name="server1"〉 〈input type="hidden" value="mysession" name="mysession"〉 〈/td〉

〈/tr〉

〈/table〉

〈/div〉

〈p〉

〈input type="submit" value="递交" name="B1" class="buttonface"〉 〈input type="reset" value="全部重写" name="B2" class="buttonface"〉

〈input type="button" value="帐号修改" onclick="location.href='admin/news_chadmin.asp'" name="B2" style="font-size:10pt;color:#000000;" class="buttonface"〉

〈input type="button" value="新闻修改" onclick="location.href='news_admin1.asp'" name="B2"

style="font-size:10pt;color:#000000;" class="buttonface"〉〈/p〉

〈/form〉

〈/body〉

〈/html〉

'###################

news_input.asp

〈!--#include file="upload.inc"--〉

〈%

'Fields("xxx").Name 取得Form中xxx(Form Object)的名字 'Fields("xxx").FilePath 如果是file Object 取得文件的完整路径 'Fields("xxx").FileName 如果是file Object 取得文件名

'Fields("xxx").ContentType 如果是file Object 取得文件的类型 'Fields("xxx").Length 取得Form中xxx(Form Object)的数据长度 'Fields("xxx").Value 取得Form中xxx(Form Object)的数据内容 Dim FormData,FormSize,gnote,bnote,notes,binlen,binstr FormSize=Request.TotalBytes

FormData=Request.BinaryRead(FormSize)

Set Fields = GetUpload(FormData)

'############判断输入错误

dim news_title,news_content,news_src,mysession

mysession=Fields("mysession").value

if len(mysession)=0 then

Response.Write "非法登陆或超时请重新登陆"

Response.End

end if

news_title=Fields("news_title").value

news_title=replace(news_title,"|","|")

news_content=Fields("news_content").value

news_src=Fields("news_src").value

news_src=replace(news_src,"|","|")

if len(news_title)=0 then%〉

〈script〉

alert("出错!新闻标题不能为空");

history.go(-1);

//window.location="news_add.asp";

〈/script〉

〈%Response.end

end if

if len(news_content)=0 then%〉

〈script〉

alert("出错!新闻内容不能为空");

history.go(-1);

〈/script〉

〈%end if

if len(news_src)=0 then%〉

〈script〉

alert("出错!新闻来源不能为空");

history.go(-1);

〈/script〉

〈%Response.end

end if

dim varchar

varchar=right(Fields("server1").value,3)

if len(varchar)〈〉0 then

if varchar〈〉"gif" and varchar〈〉"jpg" then

%〉

〈script〉

alert("出错!不能上传该图片类型");

history.go(-1);

〈/script〉

〈% Response.end

else

end if

end if

'###########将图片写入文件夹

set file_O=Server.CreateObject("Scripting.FileSystemObject")

'##########当前时间做图片名

dim newname,mytime,newfile,filename,id,image

endname=right(fields("server1").value,4)

mytime=now()

id=Year(mytime)&Month(mytime)&Day(mytime)&Hour(mytime)&Minute(MyTime)&Second(MyTime) imageid=id&endname

'#############写入图片

newfile="client1"

filename=Fields("server1").value

If Fields(newfile).FileName〈〉"" Then

file_name=Server.MapPath("./images/"&imageid&"")

set outstream=file_O.CreateTextFile(file_name,true,false)

binstr=Fields(newfile).Value

binlen=1

varlen=lenb(binstr)

for i=1 to varlen

clow = MidB(binstr,i,1)

If AscB(clow) = 255 then

outstream.write chr(255)

binlen=binlen+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

elseif AscB(clow) 〉 128 then

clow1=MidB(binstr,i+1,1)

if AscB(clow1) 〈64 or AscB(clow1) =127 or AscB(clow1) = 255 then

binlen=binlen+1

'if (binlen mod 2)=0 then

binlen=binlen+1

outstream.write Chr(AscW(ChrB(128)&clow))

'end if

notes=bnote

exit for

else

outstream.write Chr(AscW(clow1&clow))

binlen=binlen+2

i=i+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

end if

else

outstream.write chr(AscB(clow))

binlen=binlen+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

end if

next

outstream.close

set outstream=file_O.OpenTextFile(file_name,8,false,-1)

outstream.write midb(Fields(newfile).Value,binlen)

outstream.close

if notes=bnote then notes=notes&(binlen-1)&"字节处。"

End If

'###################################################################################### 把新闻数据结构写入newslist文件

dim mappath,mytext,myfso,contenttext,news_addtime,news_point

news_point=1

news_addtime=mytime

set myfso=createobject("scripting.filesystemobject")

mappath=server.mappath("./")

set mytext=myfso.opentextfile(mappath&"\new_list.asp",8,-1)

dim mytext2

if len(varchar)〈〉0 then

mytext2=trim(id&","&news_title&","&id&".txt"&","&news_src&","&news_point&","&news_addtime&","&imageid&"|")

else

mytext2=trim(id&","&news_title&","&id&".txt"&","&news_src&","&news_point&","&news_addtime&"|") end if

mytext.writeline(mytext2)

mytext.close

'##############把新闻内容写入相应的文件中

set contenttext=myfso.OpenTextFile(mappath&"\news_content\"&id&".txt",8,-1)

function htmlencode2(str) '#############字符处理函数

dim result

dim l

l=len(str)

result=""

dim i

for i = 1 to l

select case mid(str,i,1)

case chr(34)

result=result+"''"

case "&"

result=result+"&"

case chr(13)

result=result+"〈br〉"

case " "

result=result+" "

case chr(9)

result=result+" "

case chr(32)

if i+1〈=l and i-1〉0 then

if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then result=result+" "

else

result=result+" "

end if

else

result=result+" "

end if

case else

result=result+mid(str,i,1)

end select

next htmlencode2=result end function

'############################################################################ contenttext.write htmlencode2(news_content) contenttext.close set myfso=nothing

%〉 〈script〉 alert("发布成功"); window.location="news_add.asp";

〈/script〉

//新闻列表显示

〈%

dim myfso,myread

set myfso=createobject("scripting.filesystemobject")

set myread=myfso.opentextfile(server.mappath("./new_list.asp"),1,0)

if myread.atendofstream then

Response.Write "目前没有添加新闻"

Response.End

else

dim mytext,listarray

mytext=myread.readall

listarray=split(mytext,"|") '#######把所有记录分割成一个数组a

dim recordcount,pagecount, pagesize, pagenum

recordcount=ubound(listarray)'############记录条数

pagesize=2

pagecount=recordcount/pagesize '#######取得页面数

if instr(1,pagecount,".")=null or instr(1,pagecount,".")=0 then pagenum=pagecount else pagenum=int(pagecount)+1

end if dim topage

topage=cint(Request.QueryString ("topage")) '########取得要显示的页面

if topage〈=0 then topage=1 end if

if topage〉pagenum then topage=pagenum

end if

dim i,j,n b=listarray

for i=0 to recordcount-1 '########把每一条记录组成一个数组 j=split(listarray(i),",") if ubound(j)=6 then

b(i)="〈SPAN style='COLOR: #ffbd00; FONT-SIZE: 7px'〉〈li〉〈/SPAN〉〈span style='font-size:10pt'〉〈a href='news_view.asp?id=" & j(0) & "' target=blank〉" & j(1) & "(图)〈/a〉 点击:" & j(4)&"次 最后发布时间:"&j(5)&"〈/span〉" else

b(i)="〈SPAN style='COLOR: #ffbd00; FONT-SIZE: 7px'〉〈li〉〈/SPAN〉〈span style='font-size:10pt'〉〈a href='news_view.asp?id=" & j(0) & "' target=blank〉" & j(1) & "〈/a〉 点击:" & j(4)&"次 最后发布时间:"&j(5)&"〈/span〉"

end if

next

'########把记录反排序存储在新的数组实现按时间反排序

dim c(100) n=0 for i=recordcount to 0 step -1 c(n)=b(i) n=n+1

next

dim currentrecord

currentrecord=pagesize*(topage-1)+1 '#########显示每一页 for k=1 to pagesize if len(c(currentrecord))=0 then exit for end if

Response.Write c(currentrecord)&"〈br〉" currentrecord=currentrecord+1 next

Response.Write "〈body bgcolor=#EDF0F5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0〉" for m=1 to pagenum

response.write "〈span style=font-size:10pt〉〈a href=news_list.asp?topage="&m&"〉"&m&"〈/a〉〈/span〉 " next end if%>

//新闻删除

〈!--#include file="news_session.asp"--〉

〈% dim id id=Request.QueryString ("id") dim myfso

set myfso=createobject("scripting.filesystemobject") if myfso.FileExists(server.mappath("./news_content/"&id&".txt"))then

myfso.DeleteFile (server.mappath("./news_content/"&id&".txt"))'#############删除新闻内容 end if dim mytext2,myread2 set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0) if myread2.atendofstream then

Response.Write "没有新闻内容" myread2.close Response.End end if mytext2=myread2.readall myread2.close dim listarray,i,h,count,sf,title

listarray=split(mytext2,"|") '#########读取记录并以#分割成listarray数组 count=ubound(listarray)

for i=0 to count '###########根据ID找到该新闻实现删除功能 sf=split(listarray(i),",") if right(sf(0),7)=right(id,7) then dim thisid

thisid=i

'#######为6说明上传了图片,删除新闻图片和该列表记录 if ubound(sf)=6 then myfso.deletefile(server.MapPath ("./images/"&sf(6))) end if exit for

end if

next

dim mytext,mappath mappath=server.mappath("./") set mytext=myfso.createtextfile(mappath&"\new_list.asp",-1,0) for i=0 to thisid-1' ##########把所有数据重新写入文件 mytext.write listarray(i)&"|"

next for i=thisid+1 to ubound(listarray) if i=ubound(listarray) then mytext.write listarray(i) exit for else mytext.write listarray(i)&"|" end if next mytext.close

%〉

〈script language="javascript"〉

alert("删除成功");

location.href =("news_admin1.asp");

〈/script〉 --------------- news_view.asp

〈% Response.Expires=0 dim myid,myfso,myread,mytext1

myid=request.querystring("id") if len(myid)=0 then

Response.Write "没有该新闻" Response.End

end if set myfso=createobject("scripting.filesystemobject") set myread=myfso.opentextfile(server.mappath("./news_content/"&myid&".txt"),1,0) if myread.atendofstream then

Response.Write "没有新闻内容" Response.End else

mytext1=myread.readall '#######打开对应的新闻内容文件,并读取用变量存储

function htmlencode2(str)'###########字符处理函数 dim result dim l l=len(str) result="" dim i

for i = 1 to l

select case mid(str,i,1) case chr(34) result=result+"""" case "&" result=result+"&" case chr(13)

result=result+"〈br〉" case " " result=result+" " case chr(9) result=result+" "

case chr(32) result=result+" "

if i+1〈=l and i-1〉0 then

if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then result=result+" " else result=result+" " end if else

result=result+" " end if case else result=result+mid(str,i,1) end select

next htmlencode2=result

end function

myread.close

end if dim mytext2,myread2

set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0) if myread2.atendofstream then

Response.Write "没有新闻内容" Response.End

else mytext2=myread2.readall myread2.close dim listarray,i,h

listarray=split(mytext2,"|") '#########读取记录并以#分割成listarray数组 dim count,sf,title,src

count=ubound(listarray)

for i=0 to count '###########根据ID找到该新闻并把文章点击次数加1 sf=split(listarray(i),",") if right(sf(0),7)=right(myid,7) then title=sf(1) src=sf(3)

sf(4)=sf(4)+1

'#######为6说明上传了图片,存储为新的数组

if ubound(sf)=6 then listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)&","&sf(6) dim mypic mypic=sf(6) else listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)

end if '################## exit for

end if

next

dim k,mytext,mappath mappath=server.mappath("./") set mytext=myfso.createtextfile(mappath&"\new_list.asp",-1,0)

for i=0 to ubound(listarray)' ##########把所有数据重新写入文件 if i=ubound(listarray) then mytext.write listarray(i)

else mytext.write listarray(i)&"|" end if next

Response.Write "〈body bgcolor=#EDF0F5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0〉"

Response.Write"〈div align=center style=font-size:13pt〉〈strong〉"&title&"〈/strong〉〈span〉〈/div〉〈br〉"

Response.Write "〈hr size=1〉"

if len(mypic)〈〉0 then

Response.write "〈center〉〈img src='./images/"&mypic&"'〉〈/center〉"

end if

Response.Write "〈span style=font-size:10pt〉"&htmlencode2(mytext1)&"〈/span〉"

Response.Write "〈br〉〈div align=right style='font-size:9pt'〉新闻来源:〈font color=red〉"&src&"〈/font〉〈/div〉"

%〉

〈OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"〉 〈param name="Command" value="Close"〉

〈/object〉

〈center〉〈input type="button" value="关闭窗口" onclick="closes.Click();"〉〈/center〉

〈% end if%〉

//新闻修改

‘#######news_update.asp

〈!--#include file="news_session.asp"--〉

〈SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript〉

〈!--

function client_onblur(ii) {

server=eval("form1.server"+ii)

if(server.value==""){

client=eval("form1.client"+ii)

clientvalue=client.value+""

varlen=clientvalue.length

a=clientvalue.lastIndexOf('\\') clientvalue=clientvalue.substring(a+1)

//alert(clientvalue);

server.value=clientvalue

}

}

function form1_onsubmit() {

for(i=1;i〈1;i++){

client=eval("form1.client"+i)

server=eval("form1.server"+i)

if(client.value!="" && server.value==""){alert("上传后的文件名不能空!");server.focus();return false} }

}

//--〉

〈/SCRIPT〉

〈% dim myid myid=Request.QueryString ("id") if len(myid)=0 then

Response.Write "没有该新闻"

Response.End end if dim myfso,myread,mytext,newscontent

'#######打开对应的新闻内容文件,并读取用变量存储 set myfso=createobject("scripting.filesystemobject") if myfso.FileExists (server.mappath("./news_content/"&myid&".txt")) then set myread=myfso.opentextfile(server.mappath("./news_content/"&myid&".txt"),1,0)

newscontent=myread.readall

myread.close

newscontent=replace(newscontent,"〈br〉",chr(13)) newscontent=replace(newscontent," "," ") newscontent=replace(newscontent," ",chr(32)) newscontent=replace(newscontent,"'' ",chr(34))

else

Response.Write "该新闻已被删除"

Response.End end if

dim mytext2,myread2 '#######打开新闻列表文件 set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0) if myread2.atendofstream then

Response.Write "没有新闻内容" Response.End end if mytext2=myread2.readall dim listarray

listarray=split(mytext2,"|") '#########读取记录并以#分割成listarray数组 dim count,sf,i,title,src count=ubound(listarray)

for i=0 to count '###########根据ID找到该新闻并用变量存储给新闻的标题 sf=split(listarray(i),",") if right(sf(0),7)=right(myid,7) then title=sf(1) src=sf(3) exit for end if next

%〉

〈head〉

〈style〉 td {font-size:9pt} INPUT.buttonface {

BACKGROUND-COLOR: #0079F2; BORDER-BOTTOM: #333333 1px outset; BORDER-LEFT: #333333 1px

outset; BORDER-RIGHT: #ffffff 1px outset; BORDER-TOP: #ffffff 1px inset; COLOR: black; FONT-SIZE: 9pta { color: #000000; text-decoration: none} .text {font-size:11pt} INPUT.buttonface2 { BACKGROUND-COLOR: #EDF0F5; COLOR: black; FONT-SIZE: 9pta { color: #000000; text-decoration: none} a:hover { color: white; text-decoration: underline overline; background: #007EBB} .text {font-size:11pt}

〈/style〉

〈/head〉

〈body bgcolor=#EDF0F5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0〉

〈form method="POST" action="news_updateing.asp" name="form1" enctype="multipart/form-data" onsubmit="return form1_onsubmit()"〉

〈div align="left"〉

〈table border="1" width="752" height="240" cellspacing="0" cellpadding="0"〉

〈tr〉

〈td colspan="2" height="12" align="center" width="800" style="font-size:12pt"〉〈strong〉新闻发布系统后台管理--新闻修改〈/strong〉〈/td〉

〈/tr〉

〈tr〉

〈td width="119" height="12" style="font-size:9pt"〉新闻标题〈/td〉

〈td width="675" height="12"〉

〈input type="text" name="newtitle" size="94" value="〈%=title%〉" class="buttonface2 "〉

〈/td〉

〈/tr〉

〈tr〉

〈td width="119" height="213" style="font-size:9pt"〉

新〈br〉

闻〈br〉

内〈br〉

容〈/td〉

〈td width="675" height="213"〉

〈textarea rows="14" name="newcontent" cols="93" style="BACKGROUND-COLOR: #EDF0F5"〉

〈%=newscontent%〉〈/textarea〉

〈br〉

〈/td〉

〈/tr〉

〈tr〉

〈td width="119" height="4" style="font-size:9pt"〉新闻来源〈/td〉

〈td width="675" height="4"〉

〈input type=text name="newssrc" value="〈%=src%〉" size="93" class="buttonface2 "〉

〈/td〉

〈/tr〉

〈tr〉

〈td width="119" height="5" style="font-size:9pt"〉图片上传〈/td〉

〈td width="675" height="5"〉 〈input type="file" name="client1" size="20" readonly LANGUAGE=javascript onblur="return client_onblur(1)" 〉〈/td〉

〈/tr〉

〈/table〉

〈/div〉

〈p〉

〈input type="submit" value="确认" name="B1" style="font-size: 10pt; color: #000000; " class="buttonface"〉 〈input type="reset" value="全部重写" name="B2" style="font-size:10pt;color:#000000;" class="buttonface"〉 〈input type="button" value="帐号修改" onclick="location.href='admin/news_chadmin.asp'" name="B2" style="font-size:10pt;color:#000000;" class="buttonface"〉

〈input type="button" value="新闻添加" onclick="location.href='news_add.asp'" name="B2"

style="font-size:10pt;color:#000000;" class="buttonface"〉〈/p〉

〈input type=hidden name="myid" value="〈%=myid%〉"〉 〈INPUT type="hidden" name="server1"〉

〈input type="hidden" name="mysession" value="mysession"〉 〈/form〉 ########## news_updating.asp

〈!--#include file="news_session.asp"--〉

〈!--#include file="upload.inc"--〉

〈%

'Fields("xxx").Name 取得Form中xxx(Form Object)的名字 'Fields("xxx").FilePath 如果是file Object 取得文件的完整路径 'Fields("xxx").FileName 如果是file Object 取得文件名

'Fields("xxx").ContentType 如果是file Object 取得文件的类型 'Fields("xxx").Length 取得Form中xxx(Form Object)的数据长度 'Fields("xxx").Value 取得Form中xxx(Form Object)的数据内容 Dim FormData,FormSize,gnote,bnote,notes,binlen,binstr FormSize=Request.TotalBytes

FormData=Request.BinaryRead(FormSize)

Set Fields = GetUpload(FormData)

'############判断输入错误 dim mytitle,content,src,id,mysession mysession=Fields("newtitle").value if len(mysession)=0 then

Response.Write "非法登陆或超时间,请重新登陆"

Response.End end if mytitle=Fields("newtitle").value

mytitle=replace(mytitle,"|","|")

mytitle=replace(mytitle,"〈br〉","") content=Fields("newcontent").value src=Fields("newssrc").value src=replace(src,"|","|")

src=replace(src,"〈br〉","") id=trim(right(Fields("myid").value,12)) if len(mytitle)=0 then

Response.Write "〈script〉"

Response.Write "alert('出错!新闻标题不能为空!');" Response.Write"location.href=history.go(-1);"

Response.Write "〈/script〉" end if if len(content)=0 then

Response.Write "〈script〉"

Response.Write "alert('出错!新闻内容不能为空!');" Response.Write"location.href=history.go(-1);"

Response.Write "〈/script〉" end if if len(src)=0 then

Response.Write "〈script〉"

Response.Write "alert('出错!新闻来源不能为空!');" Response.Write"location.href=history.go(-1);"

Response.Write "〈/script〉"

end if '############################################################################################图片更该功能的实现

newfile="client1"

If Fields(newfile).FileName〈〉"" Then

set file_0=Server.CreateObject("Scripting.FileSystemObject") dim contextname contextname=right(Fields("client1").FileName,4) imageid=id&contextname

if contextname〈〉".gif" and contextname〈〉".jpg" then '#########判断上传文件格式 Response.Write "〈script〉"

Response.Write "alert('出错!上传文件格式不对 只能为jpg/gif图片格式!');" Response.Write"location.href=history.go(-1);"

Response.Write "〈/script〉" end if file_name=Server.MapPath("./images/"&imageid&"")

'#####################################如果原来有图片文件主名为id的则删除该图片 if file_0.fileexists(server.MapPath ("./images/"&id&".gif")) then

Set f3 = file_0.GetFile(server.MapPath ("./images/"&id&".gif")) f3.Delete

end if

if file_0.fileexists(server.MapPath ("./images/"&id&".jpg")) then

Set f3 = file_0.GetFile(server.MapPath ("./images/"&id&".jpg")) f3.Delete

end if

'########################################写入图片

set outstream=file_0.openTextFile(file_name,8,-1) binstr=Fields("client1").Value

binlen=1

varlen=lenb(binstr)

for i=1 to varlen

clow = MidB(binstr,i,1)

If AscB(clow) = 255 then

outstream.write chr(255)

binlen=binlen+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

elseif AscB(clow) 〉 128 then

clow1=MidB(binstr,i+1,1)

if AscB(clow1) 〈64 or AscB(clow1) =127 or AscB(clow1) = 255 then binlen=binlen+1

'if (binlen mod 2)=0 then

binlen=binlen+1

outstream.write Chr(AscW(ChrB(128)&clow))

'end if

notes=bnote

exit for

else

outstream.write Chr(AscW(clow1&clow))

binlen=binlen+2

i=i+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

end if

else

outstream.write chr(AscB(clow))

binlen=binlen+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

end if

next

outstream.close

set outstream=file_0.OpenTextFile(file_name,8,false,-1)

outstream.write midb(Fields(newfile).Value,binlen)

outstream.close

if notes=bnote then notes=notes&(binlen-1)&"字节处。"

End If '#######################################################################################################

dim myfso,mywrite '#######修改新闻详细内容 set myfso=createobject("scripting.filesystemobject") if myfso.FileExists(server.mappath("./news_content/"&id&".txt")) then myfso.DeleteFile (server.mappath("./news_content/"&id&".txt")) end if set mywrite=myfso.createtextfile(server.mappath("./news_content/"&id&".txt"),-1,0)

mywrite.write content

dim mytext2,myread2 '#########修改新闻的标题来源 set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0) mytext2=myread2.readall dim listarray,i,h,count,sf

listarray=split(mytext2,"|") '#########读取记录并以#分割成listarray数组

count=ubound(listarray)

for i=0 to count '###########根据ID找到该新闻记录 sf=split(listarray(i),",") if right(sf(0),7)=right(id,7) then sf(1)=mytitle sf(3)=src

'#######为6说明上传了图片,存储新的数组实现查看记录点击次数加1 if ubound(sf)=6 then

If Fields(newfile).FileName〈〉"" Then sf(6)=imageid end if listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)&","&sf(6) else listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5) end if '################## exit for

end if

next

function htmlencode2(str) '#############字符处理函数 dim result dim l l=len(str) result="" dim i for i = 1 to l

select case mid(str,i,1)

case chr(34) result=result+"''" case "&" result=result+"&" case chr(13)

result=result+"〈br〉" case " " result=result+" " case chr(9) result=result+" "

case chr(32)

if i+1〈=l and i-1〉0 then

if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then result=result+" " else result=result+" " end if else

result=result+" " end if case else result=result+mid(str,i,1) end select

next htmlencode2=result end function '##########################

dim k,mytext,mappath

mappath=server.mappath("./") set mytext=myfso.createtextfile(mappath&"\new_list.asp",-1,0) for i=0 to ubound(listarray)' ##########把所有数据重新写入文件 if i=ubound(listarray) then mytext.write htmlencode2(listarray(i)) else mytext.write htmlencode2(listarray(i)&"|") end if next

%〉

〈script language="javascript"〉

alert("更改成功"); window.location=("news_admin1.asp");

〈/script〉

相关推荐