帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
对的不足与修正建议
作者:佚名 发布时间:2005-04-02 来源:不详
 

呵呵,可以进精华区吗?用了我一天的时间。
两位张兄的<<在ASP中改善动态分页的性能>>一文给我很大的启发,在此表示感谢,但在我想来还是有一些不足的地方。

一是无法反应一些随更新的信息。
加设现为一BBS,那么随时更新的信息有
每个贴子的点击
新加贴子的信息,这些在两位张兄兄的方案中无法自动更新,只有用户在更改查询时才能使用。

二是内存使用太多,事实上对于一个论坛来讲,大多数人还是按顺序来访问的,没有必要每个人一个session。

三是处理数据时不方便
只能用数组的方式来进行,不直观,可读性差。


对于以上几点,我提出如下改进方案
一 使用application, 可做到多人共同使用同一数据
二 只存入和取出ID号,其它数据做第二次select
三 自动删除过时的application 以节约内存.
四 在添加和删除数据时,重新导入数据

其它好处
呵呵,可以使用getstring()了,原来分页时不行的
可以不用1,3了,

代码如下

a_page.asp
-----------------------------------------------------------------'
<%
dim apage_pagesize'每页记录数
dim apage_Count'总计记录数
dim apage_PageCount'总页数
dim apage_PageForm'跳页用的Form
dim apage_PageUrl'上一页下一页的链接
dim apage_timeout'过期时间设置(秒)

apage_timeout=300'过期时间设置(秒)
apage_pagesize=20'

function apage_bactive (str_name)'判断是否有这个对象,并删除过期对象
apage_bactive=false
dim item, s_temp
for item=1 to Application.contents.count '找出所有的Application
s_temp=Application.contents(item)
if isarray (s_temp) then
if ubound(s_temp)=3 and s_temp(0)="apage" then
if s_temp(1)=str_name then
apage_bactive=true'要求对象存在
else
if DateDiff("s",s_temp(2),now())>apage_timeout then '删除过其对象
Application.contents.remove(item)
end if
end if
end if
end if
next
end function??'b_inuser

sub apage_open (str_name , str_table, str_id, str_sqlend)'打开对象并计算一些数据
'对象名,表名,?关键字名, 查询条件
dim a1, a_ob
if not apage_bactive (str_name)then'如对象不存在则新建一对象
apage_load str_name, str_table, str_id, str_sqlend
end if
a1=application (str_name)
a1(2)=now()
application.lock
application (str_name)=a1
application.unlock
a_ob=a1(3)
apage_Count=ubound(a_ob,2)+1
apage_PageCount=int(apage_Count/apage_pagesize)+1
end sub'apage_open

function apage_get (str_name, page)'得到本页的所有id号
dim a1, a_ob, i_stat, i_end, i1, str_actionurl , str_query , str_1, str_2
'以下为保证page是正确的
page=cint (page)
if page <1 then page=1
if page >apage_PageCount then page=apage_PageCount

'得到id号
apage_get=""
a1=application (str_name)
a_ob=a1(3)
i_stat=(page-1)* apage_pagesize
i_end=page* apage_pagesize-1
if i_end>(apage_Count-1) then
i_end=apage_Count-1
end if

for i1=i_stat to i_end
apage_get=apage_get & a_ob(0,i1) & ","
next
'去掉多余的","号
if len(apage_get) > 0 then
apage_get=left (apage_get, len(apage_get)-1)
end if


'以下为得到用户换页信息
str_actionurl = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")
str_query=Request.ServerVariables("QUERY_STRING")
str_1=split (str_query, "&")
str_query=""
for i1=0 to ubound (str_1)
if left (str_1(i1), 5) <> "page=" then
response.write left (str_1(i1), 5) & "<br>"
str_query=str_query&str_1(i1) & "&"
end if
next
str_2=str_actionurl & "?"&str_query
if page>1 then
apage_PageUrl="<a href=" &str_2 & "page=1" &">首页</a> " & _
"<a href="&str_2 & "page="&(page-1) &">前页</a> "
else
apage_PageUrl="首页 前页"
end if
if page<apage_PageCount then
apage_PageUrl=apage_PageUrl& "<a href="&str_2 & "page="&(page+1) &">后页</a> " & _
"<a href="&str_2 & "page="&apage_PageCount&">尾页</a>"
else
apage_PageUrl=apage_PageUrl& "后页 尾页"
end if
apage_PageForm="<table><form method=get name='page' onsubmit='document.location =""" & str_2 &"page=""+this.page.value;return false;'>"&_
"<tr><td>转到第<INPUT TYPE='text' NAME='page' value='"&page&"'>页"&_
"<INPUT type=submit style='font-size: 9pt' value=GO></table>"

end function

sub apage_load (str_name, str_table, str_id, str_sqlend)'新建或重新导入一对象

sql="select " & str_id & " from " & str_table & str_sqlend
set rs=conn.execute (sql)
dim a2 (3)
a2(0)="apage"
a2(1)=str_name
a2(2)=now()
a2(3)=rs.getrows()
application.lock
application (str_name)=a2
application.unlock
end sub'apage_load

sub apage_update(str_name , str_table, str_id, str_sqlend)'更新数据时使用
if apage_bactive (str_name)then'如对象存在则重新导入对象
apage_load str_name, str_table, str_id, str_sqlend
end if
end sub

%>


附:test.asp
----------------------------------------------------------------------
<!--#include file="conn.asp" -->
<!--#include file="a_page.asp" -->
<%
'建表
'create table page
'(page_id INT?not null IDENTITY (1, 1),
'page_value int not null,
'class_id int not null
')
sub add_test'加入测试用数据
dim i1'as int
for i1=0 to 1000
sql="insert into page (page_value, class_id) values (" & i1 &",1)"
conn.execute sql
next
for i1=0 to 1000
sql="insert into page (page_value, class_id) values (" & i1 &",2)"
conn.execute sql
next
apage_update "test", "page" , "page_id" , ""
'apage_update "test1", "page" , "page_id" , " where class_id=1"
end sub 'add_test
'add_test'要加入时去掉'

dim str_test
apage_open "test", "page" , "page_id" , ""
'apage_open "test1", "page" , "page_id" , " where class_id=1"
str_test =apage_get ("test" ,request("page"))
'str_test= apage_get ("test1" ,request("page"))
sql="select??* from page where page_id in(" & str_test & ")"
set rs=conn.execute (sql)
response.write response.write "<table border=1><tr><td>" & rs.getstring (2,,"<td>", "<tr><td>") & "</table>"
'或可
'while not rs.eof
'response.write "<a href=hahafish.asp?id=" & rs("page_id") & ">" & rs("page_value") & "</a><br>"
'rs.movenext
'wend


response.write apage_PageUrl
response.write apage_pageform
%>

 
  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·J2EE项目中开发团队的组建  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统