加入收藏
联系我们
关于我们
 您现在的位置: 亿聪 >> 网络学院 >> 网络编程 >> ASP >> 正文  
  ASP深度揭密(下)       ★★★★
ASP深度揭密(下)
[ 作者:leisang    转贴自:CSDN    点击数:12554    更新时间:2004/9/29    文章录入:亿聪 ]

效果:
没有Cookies丢失!!!!

测试二维Cookies数量极限:
test_cookies_4.asp
<%
for i=1 to 301
response.cookies("tuht")("cookies_"&i)=i
next
%>


test_cookies_5.asp
<%
for i=1 to 301
response.write request.cookies("tuht")("cookies_"&i)&"<br>"
next
%>

效果:
使用这种方式可以使用201*20=4020个Cookies!!!!

3.页面过期和缓冲设定
<%
'过期和缓冲处理
response.buffer=true
response.cachecontrol="no-chache"
response.expiresabsolute=now()-1
response.expires=0
%>
html中还可以做设定:
<meta content="no-cache" http-equiv="Pragma">
<meta HTTP-EQUIV="Expires" CONTENT="0">

4.移植性的保证
⑴.包含文件
<!--#include file="top.asp" -->
⑵.使用server.mappath寻找文件路径,避免在页面中直接使用绝对路径
⑶.尽量使用组件封装业务逻辑

5.调试内部服务器500的错误
⑴.设置IIS显示具体的错误信息
⑵.分步调试,由上而下
⑶.打印某些重要的变量的值,检查是否为我们预期
⑷.根据经验来判断错误

7. 操作Word文档

⑴.安装Office 2000,其中Word 2000必选
⑵.设置IE中Internet的安全性:ActiveX控件和插件全部启用
⑶.设置工作目录的文件权为Internet及System读取/修改/写入
⑷.编写模版course.dot
⑸.具体代码:
opr_doc_inc.asp
<%
Response.write "Dim Var_Num" & chr(13)
Response.write " Var_Num = 2 " & chr(13)
Response.write "Dim varstrings(2)" & chr(13)
Response.write "varstrings(0)=" & chr(34) & "起草人:" & chr(34) & chr(13)
Response.write "varstrings(1)=" & chr(34) & "日期:" & chr(34) & chr(13)
Response.write "Dim varvalues(2)" & chr(13)
Response.write "varvalues(0)=" & chr(34) &"起草人:涂海涛"& chr(34) & chr(13)
Response.write "varvalues(1)=" & chr(34) & "日期:"&date()& chr(34) & chr(13)
%>

Sub instead(word)
Set myRange = word.ActiveDocument.Content
for i=0 to Var_Num - 1
call myRange.Find.Execute(varStrings(i),false,false,false,false,false,false,false,false,varvalues(i),2)
Next
End Sub


opr_doc.asp
<%
'获取保存的路径
path=server.mappath("opr_doc.asp")
path=left(path,len(path)-11)
filenames=path&"test.doc"

w1="word.activedocument.saveAs"&chr(32)&chr(34)&filenames&chr(34)
w2="wApp.Documents.open"&chr(32)&chr(34)&filenames&chr(34)
%>
<script language="vbscript">
On Error Resume Next
'生成指定文件名的Word文档
Dim word
set word = CreateObject("Word.Application")
if Err.number > 0 Then
Alert "发生错误,请确认文件是否存在"
else
word.visible = False
word.documents.open "<%response.write path%>course.dot"
<%Response.write w1%>
word.documents.close
set word=nothing
end if

<!--#include file="opr_doc_inc.asp"-->

Dim wApp
Set wApp = CreateObject("Word.Application")
If Err.number > 0 Then
Alert "发生错误,请确认文件是否正确创建"
else
wApp.visible = True
<%Response.write w2%>
call instead(wApp)
set wApp=nothing
end if
</script>

效果:看看生成了doc文件吗?这个新建的doc文件和模版文件有什么区别?起草人和日期发生了变化了吗?保存一下,看看新生成的doc文件的内容。


附:
1.以上全部代码在Windows 2000 Server SP2+IIS 5.0+MS SQL Server 2000+Office 2000下测试通过
2.配置数据库:数据库名course,用户course_user,密码course_password,ODBC驱动为course_dsn,端口为2433,描述表结构的脚本在共享目录下。
3.Asp fileup、Jmail、Winzip 8.1、Winzip command line这几个软件请自行下载。
4.数据库脚本文件:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[output_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[output_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[return_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[return_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[user_info_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[user_info_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[user_info_2]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[user_info_2]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[user_info_3]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[user_info_3]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[user_info]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[user_info]
GO

CREATE TABLE [dbo].[user_info] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[user_name] [varchar] (40) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[password] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[user_info] WITH NOCHECK ADD
CONSTRAINT [PK_user_info] PRIMARY KEY CLUSTERED
(
[user_name]
) ON [PRIMARY]
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE [output_1]
@sid int output
AS
set @sid=2
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE [return_1]
(@user_name varchar(40),@password varchar(20))
AS
if exists(select id from user_info where user_name=@user_name and password=@password)
return 1
else
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE [user_info_1]
(@user_name varchar(40),@password varchar(20))
AS
select id from user_info where user_name=@user_name and password=@password
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE [user_info_2]
(@user_name varchar(40),@password varchar(20))
AS
SET XACT_ABORT ON
BEGIN TRANSACTION
delete from user_info where user_name=@user_name and password=@password
COMMIT TRANSACTION
SET XACT_ABORT OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE [user_info_3] AS
select * from user_info
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

上一页  [1] [2] 

  • 上一篇文章: ASP深度揭密(上)

  • 下一篇文章: 将数字转换成大写的金额换算函数
  • 发表评论】【告诉好友】【打印此文】【关闭窗口
     最新5篇热点文章
  • Knoppix 4.0.2 免硬盘免安…[15797]

  • 通过ASP记录进行分页[20012]

  • ASP开发准则[11932]

  • ASP组件指南[11943]

  • ASP指南[11967]

  •  
     最新5篇推荐文章
  • Knoppix 4.0.2 免硬盘免安…[15797]

  • 如何让Win 2003系统更加安…[13301]

  • Nero超刻简明教程[34139]

  • PS商业实战-来杯茶,行吗?…[7255]

  • ASP深度揭密(下)[12554]

  •  
     相 关 文 章
  • ASP开发准则[11932]

  • ASP指南[11967]

  • ASP编程中15个非常有用的例…[4896]

  • ASP深度揭密(上)[11128]

  • 运行asp脚本的asp脚本[6063]


  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
        没有任何评论
    设为首页 | 加入收藏 | 关于我们 | 联系我们 | 友情链接 | 版权声明 | 管理登录
    Copyright © 2000-2022 Yicong.com.All Rights Reserved.
    亿聪 版权所有 E-mail: