JSP 페이지 내장객체 (동영상 9강 ~ 13강)
Back-End/JSP 2019. 4. 27. 23:00-JSP 내장객체-
자주사용되는 기본적인 객체
java.lang 패키지 안에 있는 기본적인 객체
import를 사용하지 않아도 기본적으로 사용가능
내장 객체 |
리턴 타입(Return Type)
|
설 명 |
request |
javax.servlet.Http.ServletRequest
|
웹 브라우저의 요청 정보를 저장하고 있는 객체 |
response |
javax.servlet.http.HttpServletResponse
|
웹 브라우저의 요청에 대한 응답 정보를 저장하고 있는 객체 |
out |
javax.servlet.jsp.jspWriter
|
JSP 페이지에 출력할 내용을 가지고 있는 출력 스트림 객체이다. |
session |
javax.servlet.http.HttpSession
|
하나의 웹 브라우저의 정보를 유지하기 위한 세션 정보를 저장하고 있는 객체 |
application |
javax.servlet.ServletContext
|
웹 어플리케이션 Context의 정보를 저장하고 있는 객체 |
pageContext |
javax.servlet.jsp.PageContext
|
JSP 페이지에 대한 정보를 저장하고 있는 객체 |
page |
java.lang.Object
|
JSP 페이지를 구현한 자바 클래스 객체 |
config |
javax.servlet.ServletConfig
|
JSP 페이지에 대한 설정 정보를 저장하고 있는 객체 |
exception |
java.lang.Throwable
|
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 |
<%@ 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/htm14/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<center>
<h2>로그인 페이지</h2>
<form action="RequestLoginProc.jsp" method="post">
<!--get 방식은 url에 내가 적은 아이디와 패스워드가 다 보인다. form은 서버에 데이터를 넘겨줄때 사용하는 명령어-->
<table width="400" border="1">
<!-- post 방식은 내가 적은 아이디와 패스워드가 암호화 되서 안보이게 된다. -->
<tr height="60">
<!-- table 태그는 border을 써야 칸이 만들어진다 -->
<td align="center" width="150">아이디</td>
<!-- tr은 1칸을 의미 -->
<td align="Left" width="250">
<!-- td는 1줄을 의미 (1행) --> <input type="text" name="id"> <!-- name를 반드시 정해야 서버에서 읽어들일 수 있다. -->
</td>
</tr>
<tr height="60">
<td align="center" width="150">패스워드</td>
<td align="Left" width="250"><input type="password"
name="pass"></td>
</tr>
<tr height="60">
<td colspan="2" align="center"><input type="submit" value="전송">
<!-- submit(전송버튼)을 누르면 action에 있는 파일(페이지로 이동)된다 --></td>
</tr>
</table>
</form>
</center>
</body>
</html> |
cs |
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 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html >
<html>
<body>
<!-- RequestLogin에서 넘어온 아이디와 패스워드를 읽어들인다. -->
<!-- [주석처리 단축키 컨트롤+쉬프트+/] -->
<!-- Request은 딱 한번만 정보의 이동이 가능하다.-->
<%
//사용자의 정보가 저장되어있는 객체 request의 getParameter() 사용자의 정보를 추출
String id = request.getParameter("id"); //사용자의 id값을 읽어들여서 변수 id에 저장한다.
String pass = request.getParameter("pass"); //form에서 넘어오는 값은 무조건 String형식으로 넘어오기 때문에 타입을 변환시키려면 데이터 타입과
//일치하는 Wrapper 클래스로 변환시켜야됨.
//int pass = Integer.parseInt(request.getParameter("pass"));
%>
<h2>
당신의 아이디는
<%=id %>
이고 패스워드는
<%=pass %>
입니다.
</h2>
</body>
</html> |
cs |
-회원가입 페이지 만들기-
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
62
63
64
65
66
67
68
69
70
71 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<center>
<h2>회원 가입</h2>
<body>
<form action="RequestJoinProc.jsp method="post">
<table width="500" border="1">
<tr height="50">
<td width="150" align="center">아이디</td>
<td width="350" align="center"><input type="text" name="id"
size="40"></td>
<tr height="50">
<td width="150" align="center">패스워드</td>
<td width="350" align="center"><input type="password"
name="pass1" size="40"></td>
<tr height="50">
<td width="150" align="center">패스워드 확인</td>
<td width="350" align="center"><input type="password"
name="pass2" size="40"></td>
<tr height="50">
<td width="150" align="center">이메일</td>
<td width="350" align="center"><input type="email"
name="email" size="40" placeholer></td>
<tr height="50">
<td width="150" align="center">전화번호</td>
<td width="350" align="center"><input type="tel" name="tel"
size="40"></td>
<tr heigth="50">
<td width="150" align="center">당신의 관심분야</td>
<td width="350" align="center"><input type="checkbox"
name="hobby" value="캠핑">캠핑 <input
type="checkbox" name="hobby" value="등산">등산 <input
type="checkbox" name="hobby" value="영화">영화 <input
type="checkbox" name="hobby" value="독서">독서 </td>
</tr>
<tr heigth="50">
<td width="150" align="center">당신의 직업은</td>
<td width="350" align="center"><select name="job">
<option value="교사">교사</option>
<option value="변호사">변호사</option>
<option value="의사">의사</option>
<option value="기술사">기술사</option>
</select></td>
</tr>
<tr height="50">
<td width="150" align="center">당신의 연령은</td>
<td width="350" align="center"><input type="radio" name="age"
value="10">10대 <input type="radio" name="age"
value="20">20대 <input type="radio" name="age"
value="30">30대 <input type="radio" name="age"
value="40">40대 </td>
</tr>
<tr height="50">
<td width="150" align="center">하고싶은말</td>
<td width="350" align="center"><textarea rows="5" cols="40"
name="info"></textarea></td>
</tr>
<tr height="50">
<td align="center" colspan="2"><input type="submit"
value="회원 가입"> <input type="reset" value="취소">
</table>
</form>
</center>
</body>
</html> |
cs |
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 62 63 64 65 66 67 68 69 70 71 72 | <%@ 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> <body> <h2>회원 정보 보기</h2> <% //post 방식으로 데이터가 넘어올때 한글이 깨질수 있기에 request.setCharacterEncoding("EUC-KR"); //각종 사용자로부터 넘어온 데이터를 저장해줌 String id = request.getParameter("id"); String pass1 = request.getParameter("pass1"); String pass2 = request.getParameter("pass2"); String email = request.getParameter("email"); String tel = request.getParameter("tel"); //[]열 타입으로 리턴 String [] hobby = request.getParameterValues("hobby"); String job = request.getParameter("job"); String age = request.getParameter("age"); String info = request.getParameter("info"); if(!pass1.equals(pass2)) { %> <script type="text/javascript"> //script 선언은 브라우저의 기본설정에 맞추어가는데 script 내부의 내용이 자바스크립트가 이닐수도 있기 때문에 alert("비밀번호가 틀립니다.");//경고창 //명시적으로 text/javascript라고 선언해준다. history.go(-1); //비밀번호가 틀릴시에는 이전 페이지로 이동 </script> <% } %> <table width="400" border="1"> <tr height="50"> <tr height="50"> <td width="150" align="center">아이디</td> <td width="350" align="center"><%=id %></td> <tr height="50"> <td width="150" align="center">이메일</td> <td width="350" align="center"><%=email %></td> <tr height="50"> <td width="150" align="center">전화번호</td> <td width="350" align="center"><%=tel %></td> <tr height="50"> <td width="200" align="center">당신의 관심분야</td> <td width="350" align="center"> <% for(int i=0; i<hobby.length; i++) //hobby는 배열이기 때문에 for문 돌려서 출력 { out.write(hobby[i]+""); } %> <tr height="50"> <td width="150" align="center">직업은</td> <td width="350" align="center"><%=job %></td> <tr height="50"> <td width="150" align="center">연령은</td> <td width="350" align="center"><%=age %></td> <tr height="50"> <td width="150" align="center">하고싶은말</td> <td width="350" align="center"><%=info %></td> </table> </body> </html> | cs |
'Back-End > JSP' 카테고리의 다른 글
19.04.28 액션 태그 (0) | 2019.04.28 |
---|---|
19.04.28 JSP의 지시자 (0) | 2019.04.28 |
웹 브라우저에서 서버로 넘어오는 파라미터 값에 한글이 있을 경우 깨짐 방지 (0) | 2019.04.27 |
19.04.27 JSP 기본 제어문 (0) | 2019.04.27 |
jsp 페이지가 실행될 때 서블릿 코드로 변환이 되는 위치 (0) | 2019.04.27 |