갈림길 이정표

[JSP] 9개 내장객체 본문

Programming Language/Servlet & JSP

[JSP] 9개 내장객체

이몽뇽 2020. 8. 26. 10:24

JSP에는 9개의 내장객체가 있다. 그중 잘 쓰이는 것은 request, response, out, session 정도 있지만 나머지 객체들도 알아보도록 하자.

더보기
  • request
  • response
  • out
  • session
  • application
  • pageContext
  • page
  • config
  • exception

[jspStart4.jsp]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
** JSP 내장객체 9개 **
<br>
request, response, out, session, (application, pageContext, page,) config, exception
<hr>
* 회원가입 * <br>
<form action="jspStart4_1.jsp" method="post" name="mem">
아이디: <input type="text" name="id" value="aa"><br>
비밀번호: <input type="text" name="pwd"><br>
작성자: <input type="text" name="name"><br>
닉네임: <input type="text" name="name"><br>	<!-- name은 배열변수로 받음 -->
하는 일: 
<select name="job">
	<option value="">직업선택</option> 
	<option value="학생">학생</option> 
	<option value="직장인">직장인</option> 
	<option value="기타">기타</option> 
</select>
<p/>
<input type="submit" value="전송">
</form>
</body>
</html>

 

[jspStart4_1.jsp]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String pwd = request.getParameter("pwd");
if(!(id.equalsIgnoreCase("aa") && pwd.equals("11"))){
	response.sendRedirect("jspStart4.jsp");	//클라이언트를 통해서 화면 바뀜
}
String[] names = request.getParameterValues("name");
String job = request.getParameter("job");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
* 회원 자료 확인 * <br>
아이디:  <% out.println(id + "<br>"); %>
이름: <%= names[0] + ", 별명은 " + names[1] + "<br>" %>
직업: <% out.println(job); %>
<hr>
기타 정보: <br>
client ip: <%= request.getRemoteAddr()%><br>
client domain: <%= request.getRemoteHost()%><br>
<!-- 자기가 자기꺼 부르면 = 0:0:0:0:0:0:0:1 -->
Method: <%=request.getMethod() %><br>

Server buffer size: <%= response.getBufferSize() %><br>

Context path: <%= application.getContextPath() %><br>
Session: <%= pageContext.getSession() %><br>
</body>
</html>

[http://localhost/web_pro4/jspStart4.jsp]에서 비밀번호 11을 입력하고 나머지 정보들을 입력하면 다음과 같이 출력이 된다.

현재는 request.getRemoteAddr( ) 및 request.getRemoteHost( ) 가 자기자신이기 때문에 0:0:0:0:0:0:0:1 이라고 나오지만 다른 사용자에서 나의 페이지에 접속을 시도할 때는 정상적으로 ip 및 도메인이 찍히게 된다.

Comments