• jsp第六次


    数据库

    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 Test2{
        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 connection=ds.getConnection();
            return connection;
        }
    }

    servlet

    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);
        }
    }
  • 相关阅读:
    kindeditor扩展粘贴截图功能&修改图片上传路径并通过webapi上传图片到图片服务器
    解决VS2015 VBCSCompiler.exe 占用CPU100%的问题
    电商网站商品模型之商品详情页设计方案
    大三那年在某宝8块钱买的.NET视频决定了我的职业生涯
    单点登录改进版-使用ajax分发cookie避免重定向轮询
    可跨域的单点登录(SSO)实现方案【附.net代码】
    使用ANTS Performance Profiler&ANTS Memory Profiler工具分析IIS进程内存和CPU占用过高问题
    js封装的三级联动菜单(使用时只需要一行js代码)
    EF查询之性能优化技巧
    EF使用CodeFirst方式生成数据库&技巧经验
  • 原文地址:https://www.cnblogs.com/iM59/p/14649234.html
Copyright © 2020-2023  润新知