`
nlx0201
  • 浏览: 28877 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

初次尝试asp编程感想

 
阅读更多

最近做了一个asp的购物网站,有点感想,分享下

1.和net不一样的是里面没有那么多对象,基本上都是过程编程,利用到的对象有response,request,server

2.逻辑代码区域使用<%%>负责

3.引用其他页面或者逻辑处理代码使用<!--#include file="xxxx.asp" -->

4.if,while,for等语句基本上都是if 条件 then 执行语句end if

5.创建数据库对象使用server.CreateObject("adodb.recordset")

6.定义对象类似var一样,都是弱类型的,这里采用vb语法dim来申明对象

下面是我的一个页面的简单代码,可以说明上面这些问题

<!--#include file="Include/Conn.asp" -->
<!--#include file="Include/function.asp" -->
<!--#include file="Include/md5.asp" -->
<%
dim username,password,comeurl
username=replace(trim(request.Form("username")),"'","")
password=md5(replace(trim(request.form("password")),"'",""),32)
if trim(request.form("comeurl"))="" then
     comeurl="member.asp"
else
     comeurl=trim(request.form("comeurl"))
end if
if username="" or password="" then
     response.Write "<script LANGUAGE='javascript'>alert('登录失败!请检查您的登录名和密码!');history.go(-1);</script>"
     response.end
end if

set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from [User] where username='"&username&"' and password='"&password&"' " ,conn,1,3
if not(rs.bof and rs.eof) then

    if password=rs("password") then
        response.Cookies("timesshop")("username")=trim(request.form("username"))
        rs("lastvst")=now()
        rs("loginnum")=rs("loginnum")+1
        rs.Update
        rs.Close
        set rs=nothing
        call loginok()
    else
        response.write "<script LANGUAGE='javascript'>alert('登录失败,请检查您的登录名和密码!');history.go(-1);</script>"
    end if
else
    response.write "<script LANGUAGE='javascript'>alert('登录失败!请检查您的登录名和密码!');history.go(-1);</script>"
end if
sub loginok()
response.Write "<font size=2>欢迎  <font color=red size=2>"&request.Cookies("timesshop")("username")&"</font>,光临两秒种后将自动跳转到相应页!</font>"
response.redirect comeurl
end sub
conn.close
set conn = nothing
%>
一直都没学过asp的语法,这次也是在原来的一个项目上做调整,也就是看一点学一点,花了一点时间算是搞定了,也对asp有了基本的了解。由于经常都是做net方面的对象编程,突然转到过程编程上来还真有点不习惯
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics