zoukankan      html  css  js  c++  java
  • 作业

    <form action="dologin.jsp" 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>
    <%
        Stu s = new Stu();
        int id = Integer.parseInt(request.getParameter("sid"));
        s.setSid(id);
        String uname = request.getParameter("uname");
        s.setUname(uname);
        String upwd = request.getParameter("upwd");
        s.setUpwd(upwd);
         
        StuDao sd=new StuDao();
        if(sd.addStu(s)>0){
            //跳转注册成功页面
        }else{
            //错误页面
        }
         %>
    
    
    <%
        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");
        }
    %>
    public int addUser(user u) throws Exception {
            int i = 0;
              Class.forName("com.mysql.jdbc.Driver");
                // 2.提供另外三个连接的基本信息
                String url = "jdbc:mysql://localhost:3306/school";
                String user = "root";
                String password = "root";
                Connection conn = DriverManager.getConnection(url, user, password);
                PreparedStatement ps = conn.prepareStatement("insert into user (uname,upwd)values(?,?)");
                ps.setString(1, u.getUname());
                ps.setString(2, u.getUpwd());
                return i = ps.executeUpdate();
                 }
    public class Login extends HttpServlet {
        @Override
        public void init() throws ServletException {
            super.init();
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            req.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=UTF-8");
            String uusername = req.getParameter("username").trim();
            String ppassword = req.getParameter("password").trim();
            int code1Int= 0;
            int code2Int= 0;
            int yzmInt= 0;
            if (code1Int+code2Int==yzmInt) {
                try {
                    String yzm = req.getParameter("verify").trim();
                    String code1 = req.getParameter("code1").trim();
                    String code2 = req.getParameter("code2").trim();
                    code1Int = Integer.parseInt(code1);
                    code2Int = Integer.parseInt(code2);
                    yzmInt = Integer.parseInt(yzm);
                    UserDao userDao = new UserDao();
                    boolean b = userDao.QueryUser(uusername, ppassword);
                    if (code1Int + code2Int == yzmInt) {
                        if (b == true) {
                            HttpSession session = req.getSession();
                            session.setAttribute("uusername", uusername);
                            req.getRequestDispatcher("index.jsp").forward(req, resp);
                        } else {
                            resp.getWriter().println("<h1>登陆失败<h1>");
                            resp.getWriter().println("<h1>用户名或密码输入错误<h1>");
                            resp.getWriter().println("<h1>5s后页面跳转....</h1>");
                            resp.getWriter().println("<a href="login.jsp">返回至登陆界面</a>");
                            resp.setHeader("Refresh", "5;url=login.jsp");
                        }
                    } else {
                        resp.getWriter().println("<h1>验证码输入错误<h1>");
                        resp.getWriter().println("<h1>3s后页面跳转....</h1>");
                        resp.getWriter().println("<a href="login.jsp">返回至登陆界面</a>");
                        resp.setHeader("Refresh", "3;url=login.jsp");
                    }
                } catch (NumberFormatException e) {
                    resp.getWriter().println("<h1>验证码为空,千万不可以为空哦<h1>");
                    resp.getWriter().println("<h1>3s后页面跳转....</h1>");
                    resp.getWriter().println("<a href="login.jsp">返回至登陆界面</a>");
                    resp.setHeader("Refresh","3;url=login.jsp");
                }
            }
        }
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            super.doGet(req, resp);
        }
    
        public void success(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
        }
    }
  • 相关阅读:
    vs2015 系统找不到指定的文件(异常来自HRESULT:0x80070002)问题的解决方法
    Quartz定时任务和IIS程序池闲置超时时间冲突解决方案
    怎样设置IIS6.0的闲置超时时间
    C#窗体如何通过keybd_event()函数模拟键盘按键(组合键)产生事件
    安装完DevExpress14.2.5,如何破解它呢?
    IIS6.0发布后对路径“D:xxxxxxxweb.config”的访问被拒绝问题的解决方法
    CentOS7 nginx+tomcat实现代理访问java web项目让项目支持jsp和php
    col-xs , col-sm , col-md , col-lg是什么意思?什么时候用?
    Linux 防火墙命令的操作命令CentOS
    Linux(centos)新建,删除,移动,重命名文件夹和文件的命令
  • 原文地址:https://www.cnblogs.com/WangYYY/p/14677880.html
Copyright © 2011-2022 走看看