일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- #성적관리프로그램
- html multimedia
- #bubbleSort
- #C++ 연산자함수오버로딩
- html code
- border-box
- git flow
- #JAVASCRIPT
- html video
- #C++ has~a
- html plug-in
- html youtube
- html charset
- 하이퍼레저패브릭
- #자바상속#자바이즈어#is~a
- #1차원배열
- html object
- html5 new tag
- html id
- #다차원포인터
- 토큰경제
- relative path
- #CallByAddress
- #binary
- #2차원배열
- hyperledger transaction
- mac terminal command
- #android activity
- docker example
- #3차원배열
- Today
- Total
A sentimental robot
간단한 웹 애플리케이션 [MODEL 1] 본문
MODEL 1
Web browser의 요청(request)을 VIEW (JSP) 에서 단독으로 처리
즉, JSP에서 VIEW와 Controller 역할을 같이 수행한다.
JSP 페이지에서 직접 Model에 접근하여 데이터를 처리한다.
Controller (Servlet) 과 Model (JavaBean) 을 만들어 분리하지 않은 방식인 모델 1 방식이다.
Login.jsp
로그인 페이지
cs
joinForm.jsp
회원가입 페이지
signup.js 회원가입 유효성 검사 joinProcess.jsp 회원가입한 회원 정보를 DB에 삽입
cs
cs
cs
loginProcess.jsp
DB에 있는 아이디와 비밀번호와 로그인 페이지에서 입력한 아이디와 비밀번호를 비교한 후 로그인 가능 여부 확인 작업
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%request.setCharacterEncoding("utf-8");%>
<%
Connection conn=null;
String id= (String)request.getParameter("id");
String pass=(String)request.getParameter("pass");
String select="select * from test";
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
Context init=new InitialContext();
DataSource ds=(DataSource)init.lookup("java:comp/env/jdbc/OracleDB");
conn=ds.getConnection();
pstmt=conn.prepareStatement(select);
rs=pstmt.executeQuery();
while (rs.next()){
//아이디와 비밀번호 비교하기
if(rs.getString(1).equals(id)){
if(rs.getString(2).equals(pass)){
session.setAttribute("id",id);
pageContext.forward("Main.jsp");
}else{
out.println("<script>alert('비밀번호가 일치하지 않습니다.'); history.back();</script>");
}
}
}
out.println("<script>alert('등록된 아이디가 없습니다.'); history.back(); </script>");
rs.close();
}catch(Exception e){
out.println("<center> <h3>Couldn't get data from DB</h3></center>");
e.printStackTrace();
}
%>
|
cs |
Main.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%request.setCharacterEncoding("utf-8");%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title></title>
</head>
<body>
<center>
<h3>Main Page</h3>
<hr>
<br>
<%
String id=(String)session.getAttribute("id");
if(id.equals("admin"))
{
out.println("<a href='Member_list.jsp'> Member List </a> <br><br>");
out.println("<a href='Member_into.jsp'> Member Information </a> <br>");
}
%>
<br>
<input type="submit" value="logout" onclick="location.href='logout.jsp'" />
</center>
</body>
</html>
|
cs |
Member_list.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%request.setCharacterEncoding("utf-8");%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title></title>
</head>
<body>
<center>
<h3> Member List </h3>
<hr>
<br>
<%
Connection conn=null;
String select="select id from test";
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
Context init=new InitialContext();
DataSource ds=(DataSource)init.lookup("java:comp/env/jdbc/OracleDB");
conn=ds.getConnection();
pstmt=conn.prepareStatement(select);
rs=pstmt.executeQuery();
while (rs.next()){
if(rs.getString(1).equals("admin")) return;
out.println("<h5>" + rs.getString(1)+ " <a href='delete.jsp?delete="+rs.getString(1)+"' > 삭제 </a></h5>");
}
rs.close();
}catch(Exception e){
out.println("<h3>Couldn't get data from DB</h3>");
e.printStackTrace();
}
%>
</center>
</body>
</html> |
cs |
delete.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%request.setCharacterEncoding("utf-8");%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title></title>
</head>
<body>
<br>
<%
Connection conn=null;
String id=request.getParameter("delete");
String delete="delete from test where id=?";
PreparedStatement pstmt=null;
ResultSet rs=null;
int n=0;
try{
Context init=new InitialContext();
DataSource ds=(DataSource)init.lookup("java:comp/env/jdbc/OracleDB");
conn=ds.getConnection();
pstmt=conn.prepareStatement(delete);
pstmt.setString(1,id);
n=pstmt.executeUpdate();
out.println("<script>alert('"+id+"님이 삭제되었습니다.');history.back();</script>");
}catch(Exception e){
out.println("<h3>Couldn't get data from DB</h3>");
e.printStackTrace();
}
%>
</body>
</html> |
cs |
Member_into.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%request.setCharacterEncoding("utf-8");%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<center>
<h3> Member Information </h3>
<hr>
<br>
<%
Connection conn=null;
String select="select * from test";
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
Context init=new InitialContext();
DataSource ds=(DataSource)init.lookup("java:comp/env/jdbc/OracleDB");
conn=ds.getConnection();
pstmt=conn.prepareStatement(select);
rs=pstmt.executeQuery();
while (rs.next()){
if(rs.getString(1).equals("admin")) return;
out.println("<h5><table border=1 cellspacing=0.5><tr><td align=center>ID</td><td>" + rs.getString(1)+"</td></tr><tr><td align=center>Pass</td><td>" + rs.getString(2) +"</td></tr><tr><td align=center>Email</td><td>"+rs.getString(3)+"</td></tr><tr><td align=center>Name</td><td>"+rs.getString(4)+"</td></tr><tr><td align=center>Address</td><td>"+rs.getString(5)+"</td></tr><tr><td align=center>Identification</td><td>"+rs.getString(6)+"</td></tr><tr><td align=center>Birth</td><td>"+rs.getString(7)+"</td></tr><tr><td align=center>Interest</td><td>"+rs.getString(8)+"</td></tr></table></h5>");
}
rs.close();
}catch(Exception e){
out.println("<h3>Couldn't get data from DB</h3>");
e.printStackTrace();
}
%>
</center>
</body>
</html> |
cs |
'Web' 카테고리의 다른 글
eclipse에서 웹서버 구축하기 (0) | 2018.10.23 |
---|---|
My error page (0) | 2018.10.23 |
jsp:forward (0) | 2018.10.23 |
회원가입 유효성 검사 (0) | 2018.10.19 |
blockRightClick(),blockSelect() (0) | 2018.10.19 |