<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page session="true" %>

<% request.setCharacterEncoding("utf-8");%>

<%
String id=request.getParameter("id");
String pw=request.getParameter("pw");
String str="";

try{
	Class.forName("oracle.jdbc.driver.OracleDriver");
	Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl","20182264","981218");
	PreparedStatement pstmt=conn.prepareStatement("select * from member_2");
	ResultSet rs= pstmt.executeQuery();
	
	while(rs.next()){
		if (id.equals(rs.getString("id")) && pw.equals(rs.getString("pw"))) {
          	session.setAttribute("id",id);
    		session.setAttribute("pw",pw);
    		response.sendRedirect("Main.jsp");
    	} else {
    		//response.sendRedirect("loginForm.jsp");
    		str="실패했습니다. 회원인지 다시 확인해 주세요";
    		//response.sendRedirect("LoginForm.jsp");
    	}
		}
	}catch(Exception e){
    		e.printStackTrace();
	}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>로그인</title>
</head>
<body>
<%=str %>
<br>

<a href="http://localhost:8080/FinalTest2/Main.jsp">메인으로 가기</a><br>
<a href="http://localhost:8080/FinalTest2/LoginForm.jsp">다시 로그인 하기</a>
</body>
</html>