ASP的javabean新用法-纯对象建站(原创)

haoru870303 2009-05-30 02:04:55
最近做了一个快餐网网站(http://www.comelife.com),最开始采用的技术是strut+hibernate+spring框架技术,不过后来考虑了下本来就是一个小网站,何况JSP的空间相对ASP空间来说贵了很多,就半途舍弃了,从而选择ASP技术支持!
在前期开发的时候设想了下,能不能做一个安全性更高,灵活性更高!可以基于这个平台演变成很多种,使自己以后开发ASP网站或做系统时都能有一个标准!
最后分析出尝试把JSP的javabean技术引用到ASP中来,说干就干,开始设计数据库,尝试着写一套公用的超做数据库的方法,公用的报错方法,验证方法!
在此贴出一部分
'// 提示框
Sub CueBox(CueBoxContent,CueURL)
Select Case CueURL
Case -1
'// 后退
Response.Write("<Script Language=""JavaScript"">alert('"& Replace( Replace( CueBoxContent , "'" , "\'" ) , """" , "\""" ) &"');window.location.href='JavaScript:history.go(-1)';</Script>")
Case -2
'// 关闭页面
Response.Write("<Script Language=""JavaScript"">alert('"& Replace( Replace( CueBoxContent , "'" , "\'" ) , """" , "\""" ) &"');window.close();</Script>")
Case -3
'// 弹出窗口
Response.Write("<Script Language=""JavaScript"">alert('"& Replace( Replace( CueBoxContent , "'" , "\'" ) , """" , "\""" ) &"');</Script>")
Exit Sub
Case Else
'// 跳转到某页
Response.Write("<Script Language=""JavaScript"">alert('"& Replace( Replace( CueBoxContent , "'" , "\'" ) , """" , "\""" ) &"');window.location.href='"& CueURL &"';</Script>")
End Select
Response.End()
End Sub
'==================================================
'函数名:ExeSql
'作 用:执行Sql语句.
'参 数: Sql --- 要执行的Sql语句
' Where -- SQl条件
' Type --- 执行模式
' Set 对象模式
' Page 分页模式
' Else 普通模式
'==================================================
Function SqlExe(Sql,StrWhere_,StrType)
'On Error Resume Next
Dim T_Rs
Select Case StrType
Case "Set"
If StrWhere_ = "" Then
Set SqlExe = Conn.Execute(Sql)
Connection_Num = Connection_Num + 1
Else
Set SqlExe = Conn.Execute(Sql & "Where" & StrWhere_)
Connection_Num = Connection_Num + 1
End If
Case "Page"
'// Sql = 表名
'// StrWhere_ = 条件
If StrWhere_ = "" Then
TotalNumber = Conn.Execute("Select Count(ID) From ["& Sql &"]")(0)
If CurrentPage = 1 Then
Sql = "Select Top " & PageSizer & " * From ["& Sql &"] Order By ID Desc"
Else
Sql = "Select Top " & PageSizer & " * From ["& Sql &"] Where Id < (Select Min(Id) As TempII From (Select Top "&(CurrentPage-1)*PageSizer&" [Id] From ["& Sql &"] Order By Id Desc) As TempTopn) Order By Id Desc"
End IF
Else
TotalNumber = Conn.Execute("Select Count(ID) From ["& Sql &"] Where "& StrWhere_ &"")(0)
If CurrentPage = 1 Then
Sql = "Select Top " & PageSizer & " * From ["& Sql &"] Where "& StrWhere_ &" Order By ID Desc"
Else
Sql = "Select Top "&PageSizer&" * From ["& Sql &"] Where "& StrWhere_ &" And Id <(Select Min(Id) As TempII From (Select Top "&(CurrentPage-1)*PageSizer&" ID From ["& Sql &"] Where "& StrWhere_ &" Order By Id Desc) As TempTopn) Order By Id Desc"
End If
End If
Set T_Rs = Conn.Execute(Sql)
If Not T_Rs.Bof Then SqlExe = T_Rs.GetRows()
T_Rs.Close
Set T_Rs = Nothing
Connection_Num = Connection_Num + 2

Case "Conn"
If StrWhere_ = "" Then
Conn.Execute(Sql)
Connection_Num = Connection_Num + 1
Else
Conn.Execute(Sql & " Where " & StrWhere_)
Connection_Num = Connection_Num + 1
End If
Case "Fun"
'// sql -- 表名
'// StrWhere_ -- 条件
SqlExe = Conn.Execute(Sql)(0)
Connection_Num = Connection_Num + 1
Case "Arr"
Set T_Rs = Conn.Execute(Sql)
If Not T_Rs.Bof Then
SqlExe = T_Rs.GetRows()
End If
T_Rs.Close
Set T_Rs = Nothing
Connection_Num = Connection_Num + 1
Case Else
Response.Write "无数据库操作!"
End Select
'//错误处理
If Err.Number <> 0 Then
Connection_Num = 0
Err.Clear
Response.Write "数据库连接错误!<Br>详细信息:无效Sql语句..请检查数据连接是否正确!</br>"&sql
Response.End()
End if
End Function

...全文
143 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
haoru870303 2009-05-30
  • 打赏
  • 举报
回复
end sub
sub DelMessage()
dim obj_mes
set obj_mes = new message
obj_mes.FileNames = "/companymanager/showmessage.asp"
obj_mes.RR_id = request("id")
obj_mes.DelMessage
set obj_mes = nothing
end sub
sub main()
If Not ChkPost() Then Call CueBox("请不要使用外部链接,错误信息:004X",-1)
end sub
%>
到这逻辑部分代码已经完全OK了接下来只需要完成页面就OK
这就是ASP的“假JAVABEAB”技术了 ,如果有兴趣的朋友要原代码的可以联系我
wenhaoboy@126.com QQ:283545622
asp技术交流群号码: 62294553
haoru870303 2009-05-30
  • 打赏
  • 举报
回复
' //添加新记录到数据库
'--------------------------------- [数据操作] -----------------------------------
Public Sub Addcompany()
R_id = SqlIn(R_id)
R_username = SqlIn(R_username)
R_password = sha256(SqlIn(R_password))
Dim IsId
IsID = SqlExe("Select Count(Id) From [table] Where [username] = '"&R_username&"'","","Fun")
If IsID >0 Then Call CueBox("["&R_username&"]用户名已经存在!错误信息:005X",-1)
Call SqlExe("Insert Into [table] ([username],[password],[companyname],[address],[name],[dcphone],[phone],[time],[stats]) Values ('"&R_username&"','"&R_password&"','"&R_companyname&"','"&R_address&"','"&R_name&"','"&R_dcphone&"','"&R_phone&"','"&R_time&"','"&R_stats&"')","","Conn")
Call CueBox("["&RR_username &"]注册成功",FileName)
End Sub
'//返回用户信息
Public Sub ShowOneCompany()
R_Id = SqlIn(R_Id)
Dim IsId
IsID = SqlExe("Select Count(Id) From [table] Where [ID] = "& R_Id &"","","Fun")
If IsID <= 0 Then Call CueBox("该用户不存在,或者传入参数有错误!错误信息:001X",-1)
Arr_cmp = SqlExe("Select * From [table] Where [Id] = "& R_Id &"","","Arr")
End Sub
Public Sub Showcmplist()
PageSizer = 10
CurrentPage = GetCurrentPage()
Arr_cmplist = SqlExe2("table",""&R_tiaojian&"","Order By vipvalue Desc","Page")
End Sub
End Class
%>
然后在完成关于用户的公用servletaction逻辑处理文件
companycommonaction.asp


<!--#include file="../common/Initialize.asp" -->
<!--#include file="../pojo/Cla_company.asp" -->
<!--#include file="../common/sha256.asp" -->
<!--#include file="../pojo/Cla_typeMun.asp" -->
<!--#include file="../pojo/Cla_CaiMun.asp" -->
<!--#include file="../pojo/Cla_message.asp" -->

<%
Select Case Request.QueryString("Action")
Case "reg"
companyreg()
Case "login"
companylogin()
case "update1"
update1()
Case "update2"
update2()
Case "buildcmp"
buildCompany()
Case "addmes"
addmessage()
Case "updateMes"
updateMessage()
Case "DelMes"
DelMessage()
Case Else
Main()
End select


sub companyreg()
DIm obj_cmp
If Not ChkPost() Then Call CueBox("请不要使用外部链接,错误信息:004X",-1)
set obj_cmp = new Company
obj_cmp.FileNames="/login.html"
'obj_cmp.RR_username = requestForm("name1","用户名不能为空","0","20","BadWord")
obj_cmp.RR_username = requestform("name1","用户名不能为空!错误信息:003X","0","20","BadWord")
obj_cmp.RR_password = request("name2")
obj_cmp.RR_companyname = REQUEST("name4")
obj_cmp.RR_address = REQUEST("name5")
obj_cmp.RR_name = request("name6")
obj_cmp.RR_phone = request("name7")
obj_cmp.RR_dcphone = request("name8")
obj_cmp.RR_time = date
obj_cmp.RR_stats = "no"
call obj_cmp.Addcompany
set obj_cmp=nothing
end sub
sub companylogin()
dim username,password,ISiD,Arr_User
If Not ChkPost() Then Call CueBox("请不要使用外部提交。错误信息:004X",-1)
UserName = Request("Name1")
PassWord =Request("name2")
PassWord = Sha256(PassWord)

'Set Rs = SqlExe("Select * From [table]","[username] = '" & SqlIn(UserName)& "'","Set")
' If Rs.Eof Then

' call cuebox(username&"用户不存在,亲重新输入!错误信息001X",-1)

IsID = SqlExe("Select Count(Id) From [table] Where [username] = '"&username &"'","","Fun")
If IsID <= 0 Then Call CueBox("该用户不存在!错误信息:001X",-1)
'Else
' If PassWord<>Rs("Password") Then
' Call CueBox("用户名或密码错误,错误信息002X",-1)

' End If
Arr_User = SqlExe("Select * From [table] Where [username] = '"&username &"'","","Arr")
If Arr_User(2,0)<>Password then
'Call CueBox("用户名或密码错误,错误信息002X",-1)
Call CueBox("用户名或密码错误,错误信息002X",-1)
else
session("company")=Arr_User
response.Redirect "/companyManager/index.asp"

End If
'Rs.Close
'Set Rs = Nothing
'response.Redirect "/companyManager/index.asp"
end sub
sub update1()
dim id,companyname,dcphone,address,zhizhao,weisheng,stime,moneyfanwei,songcanfanwei,Arr_User,companymessage
If Not ChkPost() Then Call CueBox("请不要使用外部链接,错误信息:004X",-1)
id = request("id")
companyname = requestForm("name1","店铺名不能为空!错误信息:003X","0","0","")
dcphone = requestForm("name2","订餐电话不能为空!错误信息:003X","0","0","")
address = RequestForm("name3","详细地址不能为空!错误信息:003X","0","0","")
zhizhao=requestform("name4","营业执照","2","0","BadWord")
weisheng=request("name5")
stime=request("name6")
moneyfanwei=request("name7")
companymessage=request("name8")
Call SqlExe("Update [table] Set [companyname]='"&companyname&"',[dcphone]='"&dcphone&"',[address]='"&address&"',[zhizhao]='"&zhizhao&"',[weisheng]='"&weisheng&"',[stime]='"&stime&"',[moneyfanwei]='"&moneyfanwei&"',[companymessage]='"&companymessage&"'","[ID] = "& Id &"","Conn")
Arr_User = SqlExe("Select * From [table] Where [id] = "&id &"","","Arr")
session("company")=Arr_User
Call CueBox("修改成功",-1)
'Call CueBox("修改成功,请继续装修店铺","/servletAction/companyCommon.asp?action=buildcmp")
end sub
sub update2()
dim caikey,companymessage,id,Arr_User,songcanfanwei
id = request("id")
caikey = request("name1")
songcanfanwei = request("name2")
Call SqlExe("Update [table] Set [caikey]='"&caikey&"',[songcanfanwei]='"&songcanfanwei&"'","[ID] = "& Id &"","Conn")
Arr_User = SqlExe("Select * From [table] Where [id] = "&id &"","","Arr")
session("company")=Arr_User
Call CueBox("修改成功",-1)
'Call CueBox("修改成功,请继续装修店铺","/servletAction/companyCommon.asp?action=buildcmp")
end sub
sub buildCompany()
dim folder,filepath,company,wstr,fso,fr,fw,Obj_tm,Arr_tmlist,i,Obj_cm,Arr_cmlist,ii,J,JJ
'容错处理
On Error Resume Next
company=session("company")
folder ="/shangjia/"&company(1,0)
filepath = folder&"/index.html"

set fso=createobject("scripting.filesystemobject")
set fr=fso.opentextfile(server.mappath("/temp/companyindex.html"))
wstr=fr.readall

wstr=replace(wstr,"##companyname##",company(3,0))
wstr=replace(wstr,"##songcanfanwei##",company(12,0))
wstr=replace(wstr,"##stime##",company(10,0))
wstr=replace(wstr,"##moneyfanwei##",company(11,0))
wstr=replace(wstr,"##caikey##",company(13,0))
wstr=replace(wstr,"##dcphone##",company(6,0))


Set Obj_tm = new typeMun
obj_tm.RR_cid = company(0,0)
Call Obj_tm.ShowtypeMunlist()
Arr_tmlist = Obj_tm.Arr_tmlist
Set Obj_tm = Nothing
for I= 0 to Ubound(Arr_tmlist,2)
wstr=replace(wstr,"##"&I&"muntype##",Arr_tmlist(2,I))


Set Obj_cm = new caiMun
Obj_cm.RR_tid=Arr_tmlist(0,I)
Call Obj_cm.ShowcaiMunlist2()
Arr_cmlist = Obj_cm.Arr_cmlist
Set Obj_cm = Nothing
for II= 0 to Ubound(Arr_cmlist,2)
wstr=replace(wstr,"##"&I&II&"caimunname##",Arr_cmlist(3,II))
wstr=replace(wstr,"##"&I&II&"caimunmoney##",Arr_cmlist(4,II))
next
next
for J=0 to 20
for JJ=0 to 40
wstr=replace(wstr,"##"&J&"muntype##","")
wstr=replace(wstr,"##"&J&JJ&"caimunname##","")
wstr=replace(wstr,"##"&J&JJ&"caimunmoney##","")
next
next

fso.createfolder(server.mappath(folder))
set fw=fso.createtextfile(server.mappath(filepath),true)
fw.write(wstr)

set fw=Nothing
Call CueBox("店铺装修成功","/companyManager/index.asp")
end sub
sub addmessage()
dim cid,username,message,time1,obj_mes
set obj_mes = new Message
obj_mes.FileNames = "/messagehtml/?"&request("cid")&".html"
obj_mes.RR_cid = request("cid")
obj_mes.RR_username = request("name1")
obj_mes.RR_message = request("name2")
obj_mes.RR_time = date
obj_mes.AddMessage
set obj_mes = nothing
end sub
sub updateMessage()
dim id,remessage,retime
retime= date
id = request("id")
remessage = request("name1")

Call SqlExe("Update [table] Set [remessage]='"&remessage&"',[retime]='"&retime&"'","[ID] = "& Id &"","Conn")
Call CueBox("回复成功","/companyManager/showMessage.asp")
haoru870303 2009-05-30
  • 打赏
  • 举报
回复
完成一系列的前期准备工作后尝试写注册功能
首先完成的是用户表的pojo
CLA_company.asp


<%
'================================================================
'= Power By 文豪 QQ:403665586 =
'=--------------------------------------------------------------=
'= 文件摘要:快餐系统 快餐店铺表类 =
'=--------------------------------------------------------------=
'= 系统版本:1.0 =
'= 文件版本:1.0 =
'= 文本创建日期:2009-05-18 =
'=--------------------------------------------------------------=
'================================================================
Class Company
'--------------------------------- [全局变量] -----------------------------------
Public Arr_cmp,Arr_cmplist,FileName
'--------------------------------- [局部变量] -----------------------------------
Private R_Id,R_username,R_password,R_companyname,R_address,R_name,R_time,R_dcphone,R_phone,R_zhizhao,R_weisheng,R_stime,R_moneyfanwei,R_songcanfanwei,R_caikey,R_companymessage,R_indexpath,R_stats,R_tiaojian
'--------------------------------- [公共部分] -----------------------------------
'//文件名..用于跳转
Public Property Let FileNames(StrFileName)
FileName = StrFileName
End Property
'--------------------------------- [类初始化] -----------------------------------
' Private Sub Class_Initialize()
' 'IsError = True
' 'ErrorContent = ""
' End Sub
'--------------------------------- [变量传输接口]----------------------------------

'//ID
Public Property Let RR_Id(Str)
R_Id = Str
End Property
Public Property Get RR_Id
RR_Id = R_Id
End Property

'//用户名
Public Property Let RR_username(Str)
R_username = Str

'if R_Username = "" Then call CueBox("用户名不能为空!错误信息:003X",-1)
if R_username="" Then call CueBox("用户名不能为空!",-1)
'IF LEN(R_USERNAME)<6 THEN CALL CUEBOX("客户姓名小于6个字符!",-1)
if len(R_username)<3 then call cuebox("客户姓名小于3个字符",-1)
End Property
Public Property Get RR_username
RR_username = R_username
End Property

'//密码
Public Property Let RR_password(Str)
R_password = Str
If R_password ="" Then Call CueBox("密码不能为空!错误信息:003X",-1)
IF len(R_password)<6 Then Call CueBox("密码小于6个字符!",-1)
End Property
Public Property Get RR_password
RR_password = R_password
End Property
'//快餐店铺名字
Public Property Let RR_companyname(Str)
R_companyname = Str

if R_companyname="" then call CueBox("店铺名字不能为空!错误信息:003X",-1)
IF len(R_companyname)>150 Then Call CueBox("店铺名字不能大于150个字符!",-1)
End Property
Public Property Get RR_companyname
RR_companyname = R_companyname
End Property

'//详细地址
Public Property Let RR_address(Str)
R_address = Str
If R_address ="" Then Call CueBox("详细地址不能为空.错误信息:003X",-1)

IF len(R_address)>200 Then Call CueBox("详细地址不能大于200个字符!",-1)
End Property
Public Property Get RR_address
RR_address = R_address
End Property

'//联系人
Public Property Let RR_name(Str)
R_name = Str
If R_name ="" Then Call CueBox("联系人姓名不能为空!错误信息:003X",-1)
'IF len(R_name)>100 Then Call CueBox("联系人姓名不能大于100个字符",-1)
End Property
Public Property Get RR_name
RR_name = R_name
End Property

'//常用手机
Public Property Let RR_phone(Str)
R_phone = Str
'If R_phone ="" Then Call CueBox("常用手机不能为空",-1)
'IF len(R_phone)>100 Then Call CueBox("常用手机不能大于100个字符",-1)
End Property
Public Property Get RR_phone
RR_phone = R_phone
End Property

'//订餐电话
Public Property Let RR_dcphone(Str)
R_dcphone = Str
'If R_dcphone ="" Then Call CueBox("订餐手机不能为空",-1)
'IF len(R_dcphone)>100 Then Call CueBox("订餐手机不能大于100个字符",-1)
End Property
Public Property Get RR_dcphone
RR_dcphone = R_dcphone
End Property

'//执照
Public Property Let RR_zhizhao(Str)
R_zhizhao = Str
IF len(R_zhizhao)>100 then Call CueBox("执照不能大于100字符!",-1)
End Property
Public Property Get RR_zhizhao
RR_zhizhao = R_zhizhao
End Property

'//卫生许可证
Public Property Let RR_weisheng(Str)
R_weisheng = Str
IF len(R_weisheng)>100 then Call CueBox("卫生许可证不能大于100字符!",-1)
End Property
Public Property Get RR_weisheng
RR_weisheng = R_weisheng
End Property

'//送餐时段
Public Property Let RR_stime(Str)
R_stime = Str
IF len(R_stime)>200then Call CueBox("送餐时段不能大于200字符!",-1)
End Property
Public Property Get RR_stime
RR_stime = R_stime
End Property

'//价格范围
Public Property Let RR_moneyfanwei(Str)
R_moneyfanwei = Str
IF len(R_moneyfanwei)>200then Call CueBox("送餐时段不能大于200字符!",-1)
End Property
Public Property Get RR_moneyfanwei
RR_moneyfanwei = R_moneyfanwei
End Property
'//送餐区域
Public Property Let RR_songcanfanwei(Str)
R_songcanfanwei = Str
End Property
Public Property Get RR_songcanfanwei
RR_songcanfanwei = R_songcanfanwei
End Property

'//送餐区域
Public Property Let RR_caikey(Str)
R_caikey = Str
End Property
Public Property Get RR_caikey
RR_caikey = R_caikey
End Property

'//快餐店简介
Public Property Let RR_companymessage(Str)
R_companymessage = Str
End Property
Public Property Get RR_companymessage
RR_companymessage = R_companymessage
End Property

Public Property Let RR_tiaojian(Str)
R_tiaojian = Str
End Property
Public Property Get RR_tiaojian
RR_tiaojian = R_tiaojian
End Property

Public Property Let RR_time(Str)
R_time = Str
End Property
Public Property Get RR_time
RR_time = R_time
End Property

Public Property Let RR_stats(Str)
R_stats = Str
End Property
Public Property Get RR_stats
RR_stats = R_stats
End Property

28,404

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧