zoukankan      html  css  js  c++  java
  • JSP ——第九次作业

    // 注册功能
        public boolean register(Users user) {
            Connection con = null;
            PreparedStatement ps = null;
            try {
                con = getConnection();
                String sql = "insert into users(username,password,email) values(?,?,?)";
                ps = con.prepareStatement(sql);
                ps.setString(1, user.getUsername());// 给sql语句的问号赋值
                ps.setString(2, user.getPassword());
                ps.setString(3, "aaa@qq.com");
                int row = ps.executeUpdate();
                if (row > 0) {
                    return true;
                }
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally {
                closeAll(con, ps, null);
            }
            return false;
        }
    <body>
        <form action="doregister.jsp" method="post">
            用户名:<input type="text" name="uname" /><Br> 密码 :<input
                type="password" name="upwd" /><br> <input type="submit"
                value="注册">
        </form>
    </body>
    <body>
        <%
            request.setCharacterEncoding("utf-8");
            String uname = request.getParameter("uname");
            String upwd = request.getParameter("upwd");
            Users users = new Users();
            users.setUsername(uname);
            users.setPassword(upwd);
            UsersDao ud = new UsersDao();
            if (ud.register(users)) {
                request.getRequestDispatcher("index.jsp").forward(request, response);
            } else
                response.sendRedirect("register.jsp");
        %>
    </body>
    
    doregister.jsp
    

      

    <body>
        <form action="dologin.jsp" method="post">
            用户名:<input type="text" name="uname" value="小白" /><Br> 密码 :<input
                type="password" name="upwd" value="88888" /><br> 验证码:<input
                type="text" name="validationCode"
                onKeyDown="if(event.keyCode==13){form1.submit.focus();}" size="6">
            <%
                int intmethod1 = (int) ((((Math.random()) * 5)) + 1);
                int intmethod2 = (int) ((((Math.random()) * 5)) + 1);
                int intmethod3 = (int) ((((Math.random()) * 5)) + 1);
                int intmethod4 = (int) ((((Math.random()) * 5)) + 1);
                String intsum = intmethod1 + "" + intmethod2 + intmethod3 + intmethod4;
            %>
            <input type="hidden" name="validationCode1" value="<%=intsum%>">
            <img style="height:20px;weight:20px" src="images/<%=intmethod1%>.png">
            <img style="height:20px;weight:20px" src="images/<%=intmethod2%>.png">
            <img style="height:20px;weight:20px" src="images/<%=intmethod3%>.png">
            <img style="height:20px;weight:20px" src="images/<%=intmethod4%>.png">
            <br> <input type="submit" value="登录">
        </form>
    </body>
    
    index.jsp
    

      

    <%
        request.setCharacterEncoding("utf-8");
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        UsersDao ud = new UsersDao();
        if (ud.login(uname, upwd)
                && request.getParameter("validationCode1").equals(request.getParameter("validationCode"))) {
            //登录成功,创建User对象,并放入session
            Users u = new Users();
            u.setUsername(uname);
            u.setPassword(upwd);
            session.setAttribute("user", u);
            request.getRequestDispatcher("main.jsp").forward(request, response);
        } else
            response.sendRedirect("index.jsp");
    %>
    
    dologin.jsp
    

      

  • 相关阅读:
    yii修改密码 弹出修改成功提示(八)
    yii模型规则的简单使用以及开启前端的验证(七)
    利用ab测试并发可靠么
    yii数据库链接(六)
    初始化collectionViewCell
    监听事件
    ControllerEvent
    代码构建视图
    DeveloperAppleHelp
    Xcode 小技巧
  • 原文地址:https://www.cnblogs.com/TSHEN/p/12927626.html
Copyright © 2011-2022 走看看