题目4:

请开发一个程序,当用户第一次访问时,需在线注册姓名和性别,然后把信息保存到Cookie中。当该用户再次访问时,则显示“某某先生/小姐,您好,您是 ”的欢迎信息。


效果:

效果

解题:

->unit4_4.asp

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=gb2312">
        <title>欢迎光临</title>        
    </head>
    <body>                
        <%
            dim username,sex,u,s,fname
            u = request.form("username")
            s = request.form("sex")
            response.cookies("username")=u
            response.cookies("sex")=s
            username = request.cookies("username") '读取本地cookies
            sex = request.cookies("sex")
            if username="" then
                response.write "<h3>您是第一次访问,请输入以下信息</h3>"
                response.write "<form action='' method='post'>"
                response.write "姓名:<input name='username' type='text'><br />"
                response.write "性别:<input type='radio' name='sex' value='male' checked='checked'>男<input type='radio' name='sex' value='femalemale'>女<br/><br/>"
                response.write "<input type='submit' value='注册' >&nbsp    <input type='reset'  value='重填' >"
                response.write "</form>"
            else
                fname = mid(username,1,1)
                if sex = "male" then
                    response.write  fname & "先生你好,你是:" & username
                else
                    response.write fname & "女士你好,你是:" & username
                end if
            end if                
        %>
    </body>
</html>

测试页面:

unit4_4.asp