반응형
Model 1 (기초)간략 로그인 기능 만들기..
기본적으로 오라클 DB와 연동해서 진행을 하였으며,
DB 테이블 구성은 아이디, 비밀번호, 이름, 번호 입니다.
JDK 1.8 버전
Ojdbc7 버전
login.jsp
1. 로그인 정보 입력폼(아이디, 비밀번호)
2. loginPro.jsp 로 정보 전송
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<% String id = (String)session.getAttribute("id"); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<tr>
<td>아이디<input type="text" name="id"></td>
</tr>
<tr>
<td>비밀번호<input type="text" name="pw"></td>
<td><input type="submit"></td>
</tr>
</table>
</form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
h |
Loginpro.jsp
1. login.jsp에서 받아온 파라미터를 각 변수에 할당
2. userdao 의 logincheck 메소드를 이용하여 로그인
3. 로그인 id 를 세션에 저장
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<%
if(session.getAttribute("id") == null){
System.out.println("세션만료");
}
%>
<%
request.setCharacterEncoding("euc-kr");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
UserDBDAO userdao = UserDBDAO.getInstance();
boolean check = userdao.LoginCheck(id, pw);
out.println(check);
if(check){
session.setAttribute("id", id);
out.println("로그인성공");
response.sendRedirect("main.jsp");
}
%>
<body>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
DAO LoginCheck 메소드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
public boolean LoginCheck(String id , String pwd) {
boolean check = false;
try {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String url = "jdbc:oracle:thin:@localhost:1521:XE";
String user = "dbuser";
String pw = "dbpass";
Class.forName(DriverName);
con = DriverManager.getConnection(url, user, pw);
System.out.println("로그인체크연결성공");
String sql = "select * from tbl_user where id = ? and pw = ?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1,id);
pstmt.setString(2, pwd);
rs = pstmt.executeQuery();
check = rs.next();
}catch(Exception e) {
System.out.println(e.getMessage());
}
return check;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
반응형
'JAVA' 카테고리의 다른 글
Model1 간략한 로그인 기능 만들기 - 회원정보보기(list) (0) | 2019.05.28 |
---|---|
Model1 간략한 로그인 기능 만들기 - 회원정보수정(update) (0) | 2019.05.28 |
Model1 간략한 로그인 기능 만들기 - 회원가입(Join) (0) | 2019.05.23 |
Model1 간략한 로그인 기능 만들기 - 회원가입(DTO, DAO) (0) | 2019.05.23 |
Model 1 간략한 게시판 만들기(delete.jsp) (0) | 2019.05.21 |