IT学习者 | 站长学院 | 技术文档 | 成语 | 歇后语 | 桌面壁纸 | 天气预报 | 帝国时代 | 生日密码 | 代码收藏 | 厦门天气 | IP地址查询 | 生活百科

ASP技术在论坛中的运用(八)

【 来源:CSDN 作者:佚名 更新时间:2004-09-16 | 字体:
    使用Session来保持对斑竹的身份验证,这必须要求客户端浏览器的cookie被打开了。因为Session是通过cookie来实现的。在这儿,把看板ID赋给Session变量beenthere,表明斑竹已经通过了身份验证。在后面的每个版务处理的页面中,都要检查beenthere是否和相应的看版ID相符。

  url="boardmanager.asp?boardid=" & boardid

  response.redirect url

  初学ASP的时候总是为response.redirect这个方法感到困惑,屡用不爽,现在我来告诉你一些技巧。使用它之前,必须通过response.buffer=true来让ASP页面使用缓冲区。这时,在ASP被解释成HTML代码之前,它是放在缓冲区中的,而不直接被发送的客户端浏览器。还有一个必须要知道的是:在使用response.redirect之前,是不能有任何实际的HTML代码被发送到客户端浏览器的,否则就会出错。当然也有变通的方法,如果在response.redirect之前已经有HTML代码被解释出来,可以用response.clear方法来清除缓冲区,然后就可以使用它来进行重定向了。

  end if

  %>

   

   下面的页面,就是在上面身份验证通过后重定向的目标:boardmanager.asp。它将列出了所有别有被处理的文章。

  < %

  boardid=request("boardid")

  if session("beenthere")< >boardid then response.redirect "forums.asp"

  这就是检验斑竹身份的地方,因为前面已经通过cookie在斑竹的浏览器中作了标记,现在我们就能够通过seesion来辨认斑竹的身份了。如果标志不符,就会通过response.redirect返回到最开始的登陆页面。如果斑竹浏览器的cookie没有打开,那么seesion(“beenthere“)的值会为空,同样也无法进入这个页面。

  Set conn = Server.CreateObject("ADODB.Connection")

  conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

  Set cmd = Server.CreateObject("ADODB.Command")

  Set cmd.ActiveConnection = conn

  sql="select 名称 from 看板列表 where id=" & boardid

  set rs=conn.execute(sql)

  boardname=rs("名称")

   cmd.commandtext="未发表文章列表"

   ReDim param(0) ' 声明

  param(0) = CLng(boardid) ' Cint 不可忽略

  Set rs = cmd.Execute( ,param )

  set cmd=nothing

  %>

  < html>

  < head>

  < title>版务处理< /title>

  < meta http-equiv="Content-Type" content="text/html; charset=gb2312">

  < /head>

  < body bgcolor="#FFFFFF">

  < h1 align="center">< %=boardname%>板板务管理< /h1>

  < hr>

  < %

  if rs.eof or rs.bof then response.write "< H2>现在没有文章要处理< /h2>"

  response.end

  %>

   如果没有新文章被网友发布,这给出相应的提示,并用response.end来结束此页的显示。

  < table width="90%" border="0" cellspacing="0" cellpadding="0" align="center" >

   < tr bgcolor="#FFFFCC">

   < td width="40%" height="20">主题< /td>

   < td width="40%" height="20">文章标题< /td>

   < td width="8%" height="20">作者< /td>

   < td width="12%" height="20">日期< /td>

   < /tr>

   < %

  do

  topicid=rs("主题id")

   articleid=rs("文章id")

   data=rs("日期")

  datastr=cstr(year(data)) & "-" & cstr(month(data)) &"-" & cstr(day(data))

  author=rs("作者")

   articlename=rs("标题")

   topicname=rs("主题")

  

  response.write "< tr>< td>< a href=qtopic.asp?topicid="& topicid & ">" & topicname & "< /A>< /td>"

  response.write "< td>< a href=managearticle.asp?articleid="& articleid & "&boardid=" & boardid &">" & articlename & "< /A>< /td>"

  response.write "< td>< a href=qauthor.asp?author="& author & ">" & author & "< /a>< /td>"

  response.write "< td>" & datastr & "< /td>< /tr>"

  rs.movenext

  loop until rs.eof

  %>

  < /table>

  < /html>

  < %

  set rs=nothing

  conn.close

  set conn=nothing

  %>

  < /body>

   当点击了相应文章的联结后,就进入此文章的处理页面managearticle.asp:

  < %

  articleid=request("articleid")

  boardid=request("boardid")

  if session("beenthere")< >boardid then response.redirect "forums.asp"

  Set conn = Server.CreateObject("ADODB.Connection")

  conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

  Set cmd = Server.CreateObject("ADODB.Command")

  Set cmd.ActiveConnection = conn

  cmd.CommandText = "按id查询文章"

   ReDim param(0) ' 声明

  param(0) = CLng(articleid) ' Cint 不可忽略

  Set rs = cmd.Execute( ,param )

  author=rs("作者id")

   title=rs("标题")

   data=rs("日期")

   rate=rs("推荐度")

   boardid=rs("看板id")

   topicid=rs("主题id")

   boardname=rs("看板名")

   topicname=rs("主题名")

   content=rs("内容")

  content=replace(content,vbCrlf,"< /p>< p>")

  content="< p>" & content & "< /p>"

  set cmd=nothing

  %>

  < html>

  < head>

  < title>Untitled Document< /title>

  < meta http-equiv="Content-Type" content="text/html; charset=gb2312">

  < /head>

  < body bgcolor="#E9E9E4">

  < table width="89%" border="0" cellspacing="0" cellpadding="0" align="center">

   < tr bgcolor="#CCCCCC">

   < td>作者:< font color="#FF3366">< a href="qauthor.asp?author=< %=author%>"> < %=author%> < /a>< /font> 发表日期:< font color="#FF3333">< %=data%>< /font>

   看板:< font color="#FF3333">< a href="qboard.asp?boardid=< %=boardid%>"> < %=boardname%>< /a>< /font> 板主推荐:< font color="#FF3333">#rate#< /font>< /td>

   < /tr>

   < tr bgcolor="#CCCCCC">

   < td>标题:< font color="#FF3333">< %=title%>

   主题:< a href="qtopic.asp?topicid=< %=topicid%>"> < %=topicname%> < /a> < /font>< /td>

   < /tr>

   < tr valign="top">

   < td>

   < hr>

   < font color="#FF3366">文章内容: < /font>< br>

   < br>

   < font color=blue>< %response.write content%>< /font>

   < br>

   < hr>

   < /td>

   < /tr>

   < tr valign="top">

   < form method="post" action="manageresult.asp">

   < td height="18">

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

   < tr>

   < td width="29%">

   < div align="right">

   < input type="hidden" name="boardid" value="< %=boardid%>">

   < input type="hidden" name="topicid" value="< %=topicid%>">

   < input type="hidden" name="articleid" value="< %=articleid%>">

  文章处理:< /div>

   < /td>

   < td width="12%" bordercolor="#006666">删除:

   < input type="radio" name="manage" value=1>

   < /td>

   < td width="30%" bordercolor="#006666">发表:

   < input type="radio" name="manage" value=2>

  推荐等级

   < select name="select">

   < option value="1">1< /option>

   < option value="2">2< /option>

   < option value="3" selected>3< /option>

   < option value="4">4< /option>

   < option value="5">5< /option>

   < /select>

   < /td>

   < td width="20%" bordercolor="#006666">以后在处理:

   < input type="radio" name="manage" value=3>

   < /td>

   < td width="9%">

   < input type="submit" name="Submit" value="确定">

   < /td>

   < /tr>

   < /table>

   < /td>

   < /form>

   < /tr>

  < /table>

  < /body>

  < /html>

  < %

  set rs=nothing

  conn.close

  set conn=nothing

  %>

  这一页和文章显示模块中的article.asp基本上是一样的,仅仅是多加入了斑竹处理的表单,在这儿就不多讲了。

  下面,要根据斑竹的处理过程,修该数据库相应部分:

  < %response.buffer=true%>

  < html>

  < head>

  < title>文章处理< /title>

  < meta http-equiv="Content-Type" content="text/html; charset=gb2312">

  < /head>

  < body bgcolor="#E9E9E4">

  < %

  articleid=request("articleid")

  boardid=request("boardid")

  topicid=request("topicid")

  manage=request("manage")

  ‘接受表单内容

  response.write manage ‘显示斑竹ID

  if session("beenthere")< >boardid then response.redirect "forums.asp"

  Set conn = Server.CreateObject("ADODB.Connection")

  conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

  根据上页中斑竹的操作,进行相应的处理。

  if CLng(request("manage"))=1 then

  sql="delete from 内容表 where id=" & articleid

  conn.execute sql

  response.write "< h1>文章已经被删除< /h1>"

  response.write "< a href=>back< /a>"

  elseif CLng(request("manage"))=2 then

  sql="update 内容表 set 发表=true where id=" & articleid

  conn.execute sql

  sql="update 主题表 set 文章数=文章数+1 where id=" & topicid

  conn.execute sql

  response.write "< h1>文章已经发表< /h1>"

  response.write "< a href=>back< /a>"

  else

  response.clear

  response.redirect "boardmanager.asp?boardid=" & boardid

  end if

  %>

  < /body>

  < /html>

  < %

  conn.close

  set conn=nothing

  %>

   到这儿,所有的部分就算是基本完成了。当然,这只是一个试验品,摆不上台面的。如果想要能够拿得出来的话,还要在版面设计,客户端数据验证等方面多下一些功夫。不过那都是HTML的内容了,和ASP没多大的关系,这儿就不多讲了。
  • 转载请注明来源:IT学习者 网址:http://www.itlearner.com/ 向您的朋友推荐此文章
  • 文章关键词:  ASP  论坛 
  • 特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系我们,我们会尽快予以更正。
RSS订阅
  • 抓虾
  • google reader
  • 鲜果
  • QQ邮箱

音乐
犯贱 月光 包容 想你了 甩葱歌 黄梅戏 爱情错觉 星月神话 这就是爱 最幸福的人 爱笑的眼睛 321对不起 你不知道的事 看透爱情看透你 你还欠我一个拥抱
忐忑 爱过 浮夸 猜不透 洛丽塔 错的人 爱情买卖 和平分手 等你爱我 没那么简单 我的心好冷 姑娘我爱你 在回忆中死去 我的爱情不见了 你在我心中是最美
她说 偏爱 素颜 错错错 走天涯 套马杆 断桥残雪 爱是你我 郎的诱惑 客官不可以 我要去西藏 我的好兄弟 哥只是个传说 情歌没有告诉你 我和草原有个约定
天真 王妃 小三 爱琴海 要抱抱 单身歌 埋葬冬天 给力青春 荷塘月色 最好不相见 最炫民族风 新贵妃醉酒 贝多芬的悲伤 大笑江湖主题曲 给我一个理由忘记
加入收藏留言建议ASP探针PHP探针站长Enjoy的BlogAboutDomain
© 2010 IT学习者 - itlearner.com
RunTime:18.91ms