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

 

<%@ 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>

 

posted @ 2021-04-19 18:53  -Sehnsucht  阅读(9)  评论(0编辑  收藏