zoukankan      html  css  js  c++  java
  • Web登陆实例-—同步username

        之前登陆学校的教务系统或者考试系统,进入界面都会有“欢迎***登陆本系统”。当时就认为挺高级。如今轮

    到自己做这个样例。突然感觉是so easy。

        仅仅需简单几步,就可能够搞定。

    (1)验证登陆

        编写server代码例如以下:

     protected void Page_Load(object sender, EventArgs e)
            {
                string userName = Request.Form["userName"].ToString();                     //获取username
                string userPwd = Request.Form.Get("userPwd").ToString();                    //获取password
                SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=***");   //连接数据库
                con.Open();
                SqlCommand cmd = new SqlCommand("select count(*) from login where userName='"+userName+"'  and  userPwd='"+userPwd+"'" ,con);
                int count = Convert.ToInt32(cmd.ExecuteScalar());
                if (count>0)
                {
                    Response.Redirect("main.aspx");     //验证成功
                }
                else
                {
                    Response.Redirect("loginFail.html");   //验证失败
                }
            }  

    (2)同步username

    Response.Redirect("main.aspx?userName="+userName);          //隐含的是get提交 .传入username

    //获取username:显示欢迎登陆
    string userName = Request.QueryString["userName"].ToString();          //get提交获取数据的方法
    Response.Write("<font size=24  color=red> 欢迎 " + userName + "光临本站点</font>");     //登陆后同步username 

    (3)效果




    点睛

        学习最重要的是兴趣。有时候突然非常easy的实现了自己曾经觉得非常难的事情,学习的兴趣,效率就会成几十倍,

    几百倍的添加。小小的样例。不仅巩固了我们所学的知识,并且对提高我们的学校兴趣和效率非常有帮助。


  • 相关阅读:
    大聊Python----SocketServer
    2、MySQL常见数据库引擎及比较?
    大聊Python----通过Socket实现简单的ssh客户端
    1、列举常见的关系型数据库和非关系型都有那些?
    uva12563 Jin Ge Jin Qu hao(01背包)
    UVA 12174 Shuffle(滑动窗口)
    C++中substr函数的用法
    uva11078
    11462 Age Sort(计数排序)
    UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5402256.html
Copyright © 2011-2022 走看看