HTML
sendRedirect( ) : 페이지 이동 방법 중 하나
(form에대한 개념을 잘 알고 있어야한다.)
method에서 GET과 POST (보임과 안보임)
1. GET
- 내가 친 내용이 보임
- 보안성 없음
(옛날에는 많이 사용하였으나 지금은 사용하지 않는다.)
2. POST
- 내가 친 내용이 보이지 않음 -> null로 떠야 정상
로그인 예제를 만들어 봤다.
login.jsp
result_get.jsp
end_get.jsp
result_post.jsp
end_post.jsp
jsp 파일을 만들어 준다
1.login.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 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>login</title>
</head>
<body>
<form action="result_get.jsp" method="get">
<table align="center" bgcolor="red">
<tr>
<td colspan="2" align="center">GET</td>
</tr>
<tr>
<td bgcolor="lightgrey" align="center">아이디</td>
<td><input type="text" name="id" /></td>
</tr>
<tr>
<td bgcolor="lightgrey" align="center">비밀번호</td>
<td><input type="password" name="pw" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="로그인" /></td>
</tr>
</table>
</form>
<form action="result_post.jsp" method="post">
<table align="center" bgcolor="blue">
<tr>
<td colspan="2" align="center">POST</td>
</tr>
<tr>
<td bgcolor="lightgrey" align="center">아이디</td>
<td><input type="text" name="id" /></td>
</tr>
<tr>
<td bgcolor="lightgrey" align="center">비밀번호</td>
<td><input type="password" name="pw" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="로그인" /></td>
</tr>
</table>
</form>
</body>
</html>
|
cs |
2.result_get.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 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>get</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String id = (String) request.getParameter("id");
String pw = (String) request.getParameter("pw");
request.getSession().setAttribute("id", id);
request.getSession().setAttribute("pw", pw);
%>
<%
response.sendRedirect("end_get.jsp");
%>
</body>
</html>
|
cs |
3.end_get.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 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
String id = (String) request.getSession().getAttribute("id");
String pw = (String) request.getSession().getAttribute("pw");
%>
<table align="center">
<tr>
<td colspan="2" align="center">SHOW</td>
</tr>
<tr>
<td bgcolor="lightgrey" align="center">아이디</td>
<td><%=id %></td>
</tr>
<tr>
<td bgcolor="lightgrey" align="center">비밀번호</td>
<td><%=pw %></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="뒤로가기" onclick="history.back();" /></td>
</tr>
</table>
</body>
</html>
|
cs |
4.result_post.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%!String name;%>
<%
request.setCharacterEncoding("UTF-8");
request.getSession().setAttribute("id2", (Object) request.getParameter("id"));
request.getSession().setAttribute("pw1", (Object) request.getParameter("pw"));
%>
<%
response.sendRedirect("end_post.jsp");
%>
</body>
</html>
|
cs |
5.end_post.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 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table align="center">
<tr>
<td colspan="2" align="center">SHOW</td>
</tr>
<tr>
<td bgcolor="lightgrey" align="center">아이디</td>
<td><%=request.getParameter("id")%></td>
</tr>
<tr>
<td bgcolor="lightgrey" align="center">비밀번호</td>
<td><%=request.getParameter("pw")%></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="뒤로가기" onclick="history.back();" /></td>
</tr>
</table>
</body>
</html>
|
cs |
'JSP' 카테고리의 다른 글
[JSP][JAVABEAN] (0) | 2018.04.16 |
---|---|
[JSP][introduce] (0) | 2018.04.16 |
[JSP][에러 페이지만들기] (0) | 2018.04.14 |
[JSP][장바구니 만들기] (0) | 2018.04.13 |
[JSP][jsp, 스코프 예제] (0) | 2018.04.13 |