1. 로그인 페이지 만들기!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>form demo</title>
</head>
<body>
<h1>로그인</h1>
<form name="frm" id="frm" action="login_ok.jsp" method="get">
<table border=1>
<tr>
<td>
사원아이디 </td><td><input type="text" id="eid" name="eid" value="hong" />
</td>
</tr>
<tr>
<td>
패스워드 </td><td><input type="password" id="pwd" name="pwd" value="1111" />
</td>
</tr>
<tr><td>
<input type="submit" value="로그인">
</td></tr>
</table>
</form>
</body>
</html>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*, javax.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Employee Information</title>
</head>
<body>
<%
/*
String key = "eid";
out.print(key + " = " + request.getParameter(key) + "<br>");
key = "pwd";
out.print(key + " = " + request.getParameter(key) + "<br>");
*/
String eid = "";
String pwd = "";
eid = request.getParameter("eid");
pwd = request.getParameter("pwd");
out.print("eid:" + eid + "<br>");
out.print("pwd:" + pwd + "<br>");
out.print("SELECT * FROM emp where EID='"+eid+"' AND PWD ='"+pwd+"'");
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
// Load the Oracle JDBC driver
Class.forName("oracle.jdbc.OracleDriver");
String username = "유저네임";
String password = "비밀번호";
String url = "jdbc:oracle:thin:@localhost:1521/xe";
// Establish the database connection
connection = DriverManager.getConnection(url, username, password);
// Execute a SQL query to retrieve employee information
String sqlQuery = "SELECT * FROM emp where EID='"+eid+"' AND PWD ='"+pwd+"'";
statement = connection.createStatement();
resultSet = statement.executeQuery(sqlQuery);
// Display the retrieved employee information
out.println("<table border='1'>");
out.println("<tr><th>Employee ID</th><th>Employee Name</th><th>Employee Salary</th></tr>");
while (resultSet.next()) {
int empId = resultSet.getInt("EMPNO");
String empName = resultSet.getString("ENAME");
double empSalary = resultSet.getDouble("SAL");
out.println("<tr><td>" + empId + "</td><td>" + empName + "</td><td>" + empSalary + "</td></tr>");
}
out.println("</table>");
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the resources in the reverse order of their creation
try { if (resultSet != null) resultSet.close(); } catch (Exception e) { /* ignored */ }
try { if (statement != null) statement.close(); } catch (Exception e) { /* ignored */ }
try { if (connection != null) connection.close(); } catch (Exception e) { /* ignored */ }
}
%>
</body>
</html>
'AIoT' 카테고리의 다른 글
AIoT 정규 35일차 (0) | 2024.02.20 |
---|---|
AIoT 정규 34일차 (0) | 2024.02.19 |
AIoT 정규 32일차 (0) | 2024.02.15 |
AIoT 정규 31일차 (0) | 2024.02.15 |
AIoT 정규 30일차 (2) | 2024.02.13 |