• 第七周课后作业


    用户表:  uid (主键,自动增长)   uname  upwd

    使用分层实现注册。(必做)

    使用分层实现登录。(选做)

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
      <head>
        <title>$Title$</title>
      </head>
    
      <script type="text/javascript">
        function changeActionToRegister(){
          var s = document.getElementById("idForm")
          s.setAttribute("action", "doRegister.jsp");
        }
        function changeActionToLogin(){
          var s = document.getElementById("idForm")
          s.setAttribute("action", "doLogin.jsp");
        }
      </script>
    
      <body>
    
      <form id="idForm" method="post">
        用户名:<input type="text" name="username"/>
        <br>
        密码:<input type="password"  name="password"/>
        <br>
      <input type="submit" onclick="changeActionToLogin()" value="登录">
      <input type="submit" onclick="changeActionToRegister()" value="注册">
      </form>
    
      </body>
    </html>
    <%@ page import="com.bean.lty.UserBean" %>
    <%@ page import="com.dao.lty.Dao" %>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
        <%
            UserBean userBean = new UserBean();
            String username = request.getParameter("username");
            String password = request.getParameter("password");
            userBean.setUname(username);
            userBean.setUpassword(password);
            Dao dao = new Dao();
            int i = dao.UserLogin(userBean);
            if(i > 0){
                HttpSession session1 = request.getSession();
                session1.setAttribute("username",username);
                session1.setAttribute("password",password);
                request.getRequestDispatcher("success.jsp").forward(request,response);
            }else{
                response.sendRedirect("fail.jsp");
            }
    
        %>
    </body>
    </html>
    <%@ page import="com.bean.lty.UserBean" %>
    <%@ page import="com.dao.lty.Dao" %>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    
    <%
        UserBean userBean = new UserBean();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        userBean.setUname(username);
        userBean.setUpassword(password);
        Dao dao = new Dao();
        int i = dao.UesrRegister(userBean);
        if(i > 0){
            HttpSession session1 = request.getSession();
            session1.setAttribute("username",username);
            session1.setAttribute("password",password);
            request.getRequestDispatcher("ok.jsp").forward(request,response);
        }else{
            response.sendRedirect("error.jsp");
        }
    
    %>
    
    </body>
    </html>
    package com.bean.lty;
    
    public class UserBean {
    
        private String uname;
        private String upassword;
    
        public UserBean() {
    
        }
    
        public UserBean(String uname, String upassword) {
            this.uname = uname;
            this.upassword = upassword;
        }
    
        public String getUname() {
            return uname;
        }
    
        public void setUname(String uname) {
            this.uname = uname;
        }
    
        public String getUpassword() {
            return upassword;
        }
    
        public void setUpassword(String upassword) {
            this.upassword = upassword;
        }
    }
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    您已成功注册!注册信息:用户名:<%=request.getSession().getAttribute("username")%>
    密码:<%=request.getSession().getAttribute("password")%>
    </body>
    </html>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    注册信息不正确,请重新进行注册!!!
    </body>
    </html>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    登录成功!欢迎您,用户名:<%=request.getSession().getAttribute("username")%>
    密码:<%=request.getSession().getAttribute("password")%>
    </body>
    </html>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    登录失败,用户名不存在!
    </body>
    </html>

  • 相关阅读:
    前端打印去除水印
    mybatis实现多数据库操作(个人封装注解版本)
    vue项目用hbuilder打包成APP后,返回键退出程序的解决办法
    Java迭代器Iterator的remove()方法的使用
    零基础学Java语言(浙江大学mooc)
    Oracle查询一个字段在哪张表里
    slf4j重定向日志输出
    SpringBoot嵌入pentaho-kettle工具实现数据trans转换和job任务手动执行
    Apache的karaf启动报错
    SpringBoot扩展接口- Bean实例化前后扩展点
  • 原文地址:https://www.cnblogs.com/Inati/p/14670682.html
Copyright © 2020-2023  润新知