http实现”假登录“

1.第一步用html先写出简易的用户登录注册页面:

<html>
  <head>
    <title>第一个web文件</title>
  </head>
  <body>
  <h2>欢迎学习web!</h2>
  <a href="Login.jsp">去登录</a><br>
  <a href="Zhuce.jsp">去注册</a>
  </body>
</html>

2.用HTML写出简易的的第二个登录注册页面

<html>
<head>
    <title>登录</title>
</head>
<body>
    <h1>登录</h1>
    <form action="login" method="post">
        账号:<input type="text" name="urse" value=""><br>
        密码:<input type="password" name="psw" value=""><br>
        <input type="submit" value="登录">
    </form>
</body>
</html>

3.每一个页面都对应的有一个class文件,在class文件里面用http方法实现“假登录”,例(”注册“同下):

public class Login extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Login-doGet...");
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Login-doPost...");

        // 1.从请求中获取用户提交的参数(数据)
        request.setCharacterEncoding("utf-8"); // 设置获取数据的格式
        String urse = request.getParameter("urse"); //根据表单的name属性获取用户输入的账号密码
        String psw = request.getParameter("psw");
        System.out.println(urse);
        System.out.println(psw);

        /*
         2.根据用户提交的用户名和密码---去数据库执行查询
         select * from users where urse=? and psw=?
         假登录*/
        // 3.判断成功要干什么? 判断失败要干什么?---做出响应
        response.setCharacterEncoding("utf-8"); //设置响应的编码格式
        response.setContentType("text/html:charset=UTF-8"); //以什么样的格式(文本/网页)响应
        if (urse.equals("张三")&&psw.equals("111")){
            // 登陆成功
            response.getWriter().write("登陆成功");
        }else {
            // 登陆失败
            response.getWriter().write("登陆失败");
        }

    }
}

4.发送请求到浏览器,根据用户提交的密码判断用户名和密码是否正确,做出响应:登陆成功或者登陆失败

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值