zoukankan      html  css  js  c++  java
  • 第六周 作业 张垚

    package util;
    
    import com.alibaba.druid.pool.DruidDataSourceFactory;
    
    import javax.sql.DataSource;
    import java.io.IOException;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.util.Properties;
    
    public class JDBCUtil {
        private static DataSource ds;
        static {
            Properties pro=new Properties();
            InputStream is = JDBCUtil.class.getClassLoader().getResourceAsStream("druid.properties");
            try {
                pro.load(is);
               ds = DruidDataSourceFactory.createDataSource(pro);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
        public static DataSource getDataSource(){return ds;}
        public static Connection getConnection() throws SQLException {
            Connection connectio

      

    public Doctor Login(Doctor loginDoctor) {
            try {
                String sql="select * from doctors where username = ? and password = ?";
                Doctor doctor = temp.queryForObject(sql, new BeanPropertyRowMapper<Doctor>(Doctor.class), loginDoctor.getUsername(), loginDoctor.getPassword());
                return doctor;
            } catch (DataAccessException e) {
               return null;
            }
        }
    

      

    package web.Servlet;
    
    import domain.Doctor;
    import org.apache.commons.beanutils.BeanUtils;
    import service.DoctorService;
    import service.impl.DoctorServiceImpl;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.util.Map;
    
    
    

     

    @WebServlet("/LoginServlet")
    public class LoginServlet extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("utf-8");
            String checkCode = request.getParameter("checkCode");
            HttpSession session = request.getSession();
            String checkcode = (String) session.getAttribute("CHECKCODE_SERVER");
            if (!checkcode.equalsIgnoreCase(checkCode)){
                request.setAttribute("error_msg","验证码错误");
                request.getRequestDispatcher("/index.jsp").forward(request,response);
                return;
            }
            Map<String, String[]> map = request.getParameterMap();
            Doctor loginDoctor =new Doctor();
            try {
                BeanUtils.populate(loginDoctor,map);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
            DoctorService service=new DoctorServiceImpl();
            Doctor doctor=service.Login(loginDoctor);
            if (doctor!=null){
                session.setAttribute("user",doctor);
                response.sendRedirect(request.getContextPath()+"/Home.jsp");
            }else {
                request.setAttribute("error_msg","用户名或密码错误");
                request.getRequestDispatcher("/index.jsp").forward(request,response);
            }
    
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request, response);
        }
    }
    

      

     

     

  • 相关阅读:
    学习Karma+Jasmine+istanbul+webpack自动化单元测试
    学习测试框架Mocha
    WebSockets通信
    简单的CSS圆形缩放动画
    css3 实现图片等比例放大与缩小
    CSS3之多列布局columns详解
    scp传输文件的命令
    学习rollup.js模块文件打包
    go语言之进阶篇通过switch实现类型断言
    go语言之进阶篇通过if实现类型断言
  • 原文地址:https://www.cnblogs.com/ZXCVBNM1314/p/14649521.html
Copyright © 2011-2022 走看看