好久没有写过asp了,这回写个留言板还真觉得有点难度,竞然写了整整一天,哈哈. 演示www.zj55.com的留言板,希望各位大哥大姐如果发现有漏洞的话请在这里告诉我,千万不要黑我的网站,在这里小弟先谢过了. index.asp BLL_Guest.asp Private mycom,mymod,mydal Private LI,UL Private DEL mydal.GetGuest(Id) End Sub 新增信息 Call mydal.Insert(mymod) End Sub 更新信息 Call mydal.Update(mymod) End Sub 删除信息 mydal.Delete(Request(“Id”)) End Sub 查找信息 Dim PageSize,CurrentPage,WhereValue,OrderValue,RecordCount FindByPage = tmp2 End Function Private Sub Class_Initialize() LI = “<li><span>{0}</span> <span>{1}</span><br /><span>作者:{2}</span> <span>{3}</span> <span>{4}</span></li>” & vbCrLf Set mycom = new Common End Sub Private Sub Class_Terminate() Set mycom = Nothing End Sub End Class DAL_Guest.asp Private mycom,myacc,mymod /// <summary> Dim parms,SQL,objRS /// <summary> Dim parms,SQL End Sub /// <summary> End Sub /// <summary> Dim parms,SQL End Sub /// <summary> Dim parms,SQL,objRS End Function /// <summary> Dim parms,SQL,objRS Set objRS = myacc.ExecuteReader(myacc.CONN_STRING,SQL) SQL_01 = “Select * From [Guest] Where Id = {0}” Set mycom = new Common End Sub Private Sub Class_Terminate() Set mycom = Nothing End Sub End Class MOD_Guest.asp Public Id Public Sub SetVar(vId,vContent,vRe,vAddtime,vIp) End Class Common.asp /// <summary> Dim r,i End Function Public Function Page(PageSize,CurrentPage,RecordCount,PageUrl) If RecordCount Mod PageSize <> 0 Then if CInt(CurrentPage)>1 Then if CInt(CurrentPage)<PageCount Then parms=Array(CurrentPage,PageCount) End Function End Class AccHelper.asp Public CONN_STRING /// <summary> End Function /// <summary> End Function /// <summary> End Function Private Sub Class_Initialize() End Class
就只有留言其它的都什么也没写,采用三层结构(不知道算不算,本来对三层的概念很糊涂)
<%@ codepage=65001%>
<%
option explicit
%>
<% Response.Charset=”utf-8″%>
<% Session.CodePage=65001 %>
<!– #include file=”AccHelper.asp” –>
<!– #include file=”Common.asp”–>
<!– #include file=”DAL_Guest.asp” –>
<!– #include file=”MOD_Guest.asp” –>
<!– #include file=”BLL_Guest.asp” –>
<%
Dim mybll
Dim myList
Set mybll = new BLL_Guest
Select Case Request(“tCMD”)
Case “SAVE”
mybll.Insert()
Case “DEL”
mybll.Delete()
End Select
myList = mybll.FindByPage()
%>
<h2>客户留言</h2>
<p>
<form name=”subForm” id=”subForm”>
<textarea id=”con” name=”con” cols=”56″ rows=”6″ wrap=”VIRTUAL”></textarea>
<input type=”button” name=”submit” value=”提交留言” onclick=”$(guest/index.asp?tCMD=SAVE&content=+escape(this.form.con.value))” />
</form>
</p>
<%=myList%>
<%
/// <summary>
/// 摘要说明。
/// </summary>
Class BLL_Guest
获取信息
Public Sub GetGuest()
Public Sub Insert()
mymod.Content = Request(“content”)
mymod.re = Request(“Re”)
mymod.Addtime = Now()
mymod.Ip = request.servervariables(“HTTP_X_FORWARDED_FOR”)
If len(mymod.Ip)<=0 Then mymod.Ip = request.servervariables(“REMOTE_ADDR”)
Public Sub Update()
Public Sub Delete()
Public Function FindByPage()
Dim objRS
Dim tmp1,tmp2,tmp3,parms,i
Dim tCMD
tCMD = Request(“tCMD”)
PageSize = “8”
CurrentPage = Request(“PageNo”)
If Len(CurrentPage)<=0 Then
CurrentPage=1
End If
WhereValue = “”
OrderValue = “Id”
Set objRS = mydal.FindByPage(PageSize,CurrentPage-1,WhereValue,OrderValue)
i = 1
RecordCount = mydal.Count(WhereValue)
Do While Not objRS.EOF
If tCMD=”DEL” Then
DEL = “<a href=””?tCMD=DEL&Id=”&objRS(“Id”)&”””>删除</a>”
Else
DEL = “”
End If
parms=Array(i,objRS(“content”),objRS(“ip”),objRS(“addtime”),DEL)
tmp1 = tmp1 & mycom.Format(LI,parms)
objRs.Movenext
i = i + 1
Loop
tmp3 = mycom.Page(PageSize,CurrentPage,RecordCount,”guest/index.asp?tCMD=LIST”)
parms=Array(tmp1,tmp3)
tmp2 = tmp2 & mycom.Format(UL,parms)
UL = “<UL>{0}<li>{1}</li></UL>”
DEL = “”
set mymod = new MOD_Guest
set mydal = new DAL_Guest
Set mymod = Nothing
set mydal = Nothing
%>
<%
/// <summary>
/// 摘要说明。
/// </summary>
Class DAL_Guest
Private SQL_01
Private SQL_02
Private SQL_03
Private SQL_04
Private SQL_05
Private SQL_06
Private SQL_07
/// 获得信息
/// </summary>
/// <param name=”Id”>判断字段</param>
/// <returns>信息体</returns>
Public Function GetGuest(Id)
parms = Array(Id)
SQL = mycom.Format(SQL_01,parms)
Set objRS = myacc.ExecuteReader(myacc.CONN_STRING,SQL)
If Not objRS.EOF then
Call mymod.SetVar(objRs(“Id”),objRs(“Content”),objRs(“Re”),objRs(“Addtime”),objRs(“Ip”))
Set GetGuest = mymod
Else
GetGuest = Null
End If
End Function
/// 插入信息
/// </summary>
/// <param name=””>信息体</param>
Public Sub Insert(vmod)
parms = Array(vmod.Content,vmod.Re,vmod.Addtime,vmod.Ip)
SQL = mycom.Format(SQL_02,parms)
Call myacc.ExecuteReader(myacc.CONN_STRING,SQL)
/// 更新信息
/// </summary>
/// <param name=””>信息体</param>
Public Sub Update(vmod)
Dim parms,SQL
parms = Array(vmod.Id,vmod.Content,vmod.Re,vmod.Addtime,vmod.Ip)
SQL = mycom.Format(SQL_03,parms)
Call myacc.ExecuteReader(myacc.CONN_STRING,SQL)
/// 删除信息
/// </summary>
/// <param name=””>信息体</param>
Public Sub Delete(Id)
parms = Array(Id)
SQL = mycom.Format(SQL_04,parms)
Call myacc.ExecuteNonQuery(myacc.CONN_STRING,SQL)
/// 统计信息
/// </summary>
/// <param name=””>信息体</param>
Public Function Count(WhereValue)
parms = Array(WhereValue)
SQL = mycom.Format(SQL_07,parms)
Set objRS = myacc.Recordset(myacc.CONN_STRING,SQL)
Count = objRS.RecordCount
/// 根据条件列出所有信息(带有分页)
/// </summary>
/// <param name=”PageSize”>每页记录数</param>
/// <param name=”CurrentPage”>页码</param>
/// <param name=”WhereValue”>判断值</param>
/// <param name=”OrderValue”>排序</param>
/// <returns>返回objRS</returns>
Public Function FindByPage(PageSize,CurrentPage,WhereValue,OrderValue)
Dim s1
If CurrentPage=”0″ Then
s1 = PageSize & “|” + OrderValue & “|” & WhereValue
parms = Split(s1,”|”)
SQL = mycom.Format(SQL_05,parms)
Else
s1 = PageSize & “|” & OrderValue & “|” + WhereValue & “|” & CurrentPage*PageSize
parms = Split(s1,”|”)
SQL = mycom.Format(SQL_06,parms)
End If
Set FindByPage = objRS
End Function
Private Sub Class_Initialize()
SQL_02 = “Insert into [Guest] ([Content],[Re],[Addtime],[Ip]) values({0},{1},{2},{3})”
SQL_03 = “Update [Guest] Set [Content]={1},[Re]={2},[Addtime]={3},[Ip]={4} Where Id = {0}”
SQL_04 = “Delete From [Guest] Where Id In ({0})”
SQL_05 = “Select Top {0} * From [Guest] Where Content Like %{2}% Order By {1} Desc,Id Desc”
SQL_06 = “Select Top {0} * From [Guest] Where Content Like %{2}% And Id Not IN(Select Top {3} Id From [Guest] Where Content Like %{2}% Order By {1} Desc,Id Desc) Order By {1} Desc,Id Desc”
SQL_07 = “Select * From [Guest] Where Content Like %{0}% “
Set myacc = new AccHelper
Set mymod = new MOD_Guest
Set myacc = Nothing
Set mymod = Nothing
%>
<%
/// <summary>
/// 摘要说明。
/// </summary>
Class MOD_Guest
Public Content
Public Re
Public Addtime
Public Ip
Id=vId
Content=vContent
Re=vContent
Addtime=vAddtime
Ip=vIp
End Sub
%>
<%
/// <summary>
/// 摘要说明
/// </summary>
Class Common
/// 获得信息
/// </summary>
/// <param name=”Id”>需要内容</param>
/// <param name=”Id”>替换关键字</param>
/// <returns>格式化后内容</returns>
Public Function Format(str,arr)
r = str
For i = 0 To UBound(arr)
r = Replace(r,”{“&i&”}”,arr(i))
Next
Format = r
const C_RECORDCOUNT = “合计<STRONG><FONT color=””red””>{0}</FONT></STRONG>篇 |”
const C_FIRSTPAGE1 = “ <a href=””#”” onclick=””$({0}&PageNo={1})””>首页</a>”
const C_FIRSTPAGE2 = “ 首页”
const C_PREVPAGE1 = “ <a href=””#”” onclick=””$({0}&PageNo={1})””>上一页</a>”
const C_PREVPAGE2 = “ 上一页”
const C_NEXTPAGE1 = “ <a href=””#”” onclick=””$({0}&PageNo={1})””>下一页</a>”
const C_NEXTPAGE2 = “ 下一页”
const C_LASTPAGE1 = “ <a href=””#”” onclick=””$({0}&PageNo={1})””>尾页</a>”
const C_LASTPAGE2 = “ 尾页”
const C_CURRENTPAGE = “ 页次:<STRONG><FONT color=””red””>{0}</FONT>/{1}</STRONG>页”
const C_PAGESIZE = “ <STRONG>{0}</STRONG>篇/页 ”
const C_GOTOPAGE = “ 跳转:<input type=””text”” name=””goto”” value=””{1}”” onchange=””$({0}&PageNo=+this.value)”” style=””width:20px;border:1px””/> ”
Dim PageCount,pages
Dim lRecordCount,lFirstpage,lPrevpage,lNextpage,lLastpage,lCurrentpage,lPagesize,lGotopage
Dim p,parms
pages = 1
else
pages = 0
End If
PageCount=CInt(RecordCount/PageSize + pages)
parms=Array(RecordCount)
lRecordCount = Format(C_RECORDCOUNT,parms)
parms=Array(Pageurl,1)
lFirstpage = Format(C_FIRSTPAGE1,parms)
parms=Array(Pageurl,CInt(CurrentPage)-1)
lPrevpage = Format(C_PREVPAGE1,parms)
Else
lFirstpage=C_FIRSTPAGE2
lPrevpage=C_PREVPAGE2
End If
parms=Array(Pageurl,CInt(CurrentPage)+1)
lNextpage = Format(C_NEXTPAGE1,parms)
parms=Array(Pageurl,CInt(CurrentPage)+1)
lLastpage = Format(C_LASTPAGE1,parms)
Else
lNextpage=C_NEXTPAGE2
lLastpage=C_LASTPAGE2
End If
lCurrentpage = Format(C_CURRENTPAGE,parms)
parms=Array(PageSize)
lPagesize = Format(C_PAGESIZE,parms)
parms=Array(Pageurl,CurrentPage)
lGotopage = Format(C_GOTOPAGE,parms)
p=lRecordCount&lFirstpage&lPrevpage&lNextpage&lLastpage&lCurrentpage&lPagesize&lGotopage
Page = p
%>
<%
/// <summary>
/// AccHelper 的摘要说明。
/// </summary>
Class AccHelper
/// 执行ExecuteNonQuery
/// </summary>
/// <param name=”connString”>连接字符</param>
/// <param name=”cmdText”>sql命令</param>
Public Function ExecuteNonQuery(connString,cmdText)
Dim objConn
Set objConn = Server.CreateObject(“ADODB.Connection”)
objConn.Open connString
objConn.Execute(cmdText)
/// 执行ExecuteReader
/// </summary>
/// <param name=”connString”>连接字符</param>
/// <param name=”cmdText”>sql命令</param>
/// <returns>RS</returns>
Public Function ExecuteReader(connString,cmdText)
Dim objConn,objRS
Set objConn = Server.CreateObject(“ADODB.Connection”)
objConn.Open connString
Set objRS = objConn.Execute(cmdText)
Set ExecuteReader = objRS
/// 执行Recordset
/// </summary>
/// <param name=”connString”>连接字符</param>
/// <param name=”cmdText”>sql命令</param>
/// <returns>RS</returns>
Public Function Recordset(connString,cmdText)
Dim objConn,objRS
Set objConn = Server.CreateObject(“ADODB.Connection”)
objConn.Open connString
Set objRS = Server.CreateObject(“ADODB.RecordSet”)
objRS.Open cmdText,objConn,1,3
Set Recordset = objRS
CONN_STRING = “provider = microsoft.jet.oledb.4.0;data source=” & Server.Mappath(“db.mdb”)
End Sub
%>
asp简单的ajax留言板(采用三层模式)_ajax教程
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » asp简单的ajax留言板(采用三层模式)_ajax教程
相关推荐
-      Jquery处理Json字符串的实例
-      ASP+Ajax实现无刷新评论简单例子
-      AJAX的阻塞及跨域名解析
-      AJAX学习资料
-      [js]一个获取页面ip的正则
-      ajax用户注册代码
-      each循环输出jquery返回的json字符串
-      Ajax技术全解之一