• jsp第七次作业


    package org.mbw.dao;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import org.mbw.entity.Login;
    
    public class LoginDao {
            public static int login(Login Login) {
                //boolean flag = false;
                int flag = -1 ;
                int result = -1;
                String URL = "jdbc:mysql://localhost:3306/move?useSSL=false&useUnicode=true&characterEncoding=UTF-8";
                String USERNAME = "root";
                String PWD = "123456";
                
                Connection connection = null;
                PreparedStatement ps = null;
                ResultSet rs = null;
                
                try {
                    Class.forName("com.mysql.jdbc.Driver");
                    connection = DriverManager.getConnection(URL, USERNAME, PWD);
                    
                    String sql = "select count(*) from user where uname = ? and pwsd = ?";
                    ps = connection.prepareStatement(sql);
                    ps.setString(1, Login.getUname());
                    ps.setString(2, Login.getPwsd());
                    rs = ps.executeQuery();
                    if(rs.next()) {
                        result = rs.getInt(1);
                    }
                    if(result>0) {
                        return 1;
                    }else {
                      return 0;
                    }
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                    return -1;
                }catch(SQLException e) {
                    e.printStackTrace();
                    return -1;
                }catch(Exception e) {
                    e.printStackTrace();
                    return -1;
                }finally {
                    try {
                    if(rs!=null) rs.close();
                    if(ps!=null) rs.close();
                    if(connection!=null) rs.close();
                    }catch(SQLException e) {
                        e.printStackTrace();
                    }catch(Exception e) {
                        e.printStackTrace();
                    }
                }
            }
    }
    
    
    package org.mbw.entity;
    
    public class Login {
           private int id;
           private String uname;
           private String pwsd;
           
       public Login() {
    }
       
       public Login(String uname, String pwsd) {
            this.uname = uname;
            this.pwsd = pwsd;
        }
        public Login(int id, String uname, String pwsd) {
            this.id = id;
            this.uname = uname;
            this.pwsd = pwsd;
        }
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getUname() {
            return uname;
        }
        public void setUname(String uname) {
            this.uname = uname;
        }
        public String getPwsd() {
            return pwsd;
        }
        public void setPwsd(String pwsd) {
            this.pwsd = pwsd;
        }
           
           
    }
    
    
    
    package org.mbw.servlet;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.mbw.dao.LoginDao;
    import org.mbw.entity.Login;
    
    
    public class LoginServlet extends HttpServlet {
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("utf-8");
            String name = request.getParameter("uname");
            String pwd = request.getParameter("upwsd");
            Login login = new Login(name,pwd);//用户名,密码
            
            int result = LoginDao.login(login);
            if(result>0) {
                response.sendRedirect("Welcome.jsp");
            }else {
                response.sendRedirect("login.jsp");
            }
        }
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
        }
    
    }
  • 相关阅读:
    jquery清空下拉框,保留第一个
    [转]js和jquery获取窗体高度
    点击回车 按钮不执行点击事件
    时间戳 Date.parse()和dateObject.getTime()的区别
    uni-app 时间格式问题 new Date(str) IOS系统跟Android系统不兼容
    uni-app 使用 iconfont 图标 自定义图标
    uni-app 使用Vuex+ (强制)登录
    uni-app 保持登录状态 (Vuex)
    package.json和npm install、cnpm install 的問題
    如何将baseUrl项目地址提取放到放到static
  • 原文地址:https://www.cnblogs.com/527x/p/14674326.html
Copyright © 2020-2023  润新知