JSP/내장 객체
out 내장 객체
별초롱언니
2025. 5. 24. 07:23
out 내장 객체는 웹 브랑줘에 데이터를 전송하는 출력 스트림 객체입니다. JSP 컨테이너는 JSP 페이지에 사용되는 모든 표현문 태그와 HTML, 일반 텍스트 등을 out 내장 객체를 통해 웹 브라우저에 그대로 전달합니다. out 내장 객체는 스크립틀릿 태그에 사용하여 단순히 값을 출력하는 표현문 태그<%= ... %>와 같은 결과를 얻을 수 있습니다.
<%@ 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>
<h3>회원가입</h3>
<form action="form01" name="member" method="get">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복 검사">
<p> 비밀번호 : <input type="password" name="passwd">
<p> 이름 : <input type="text" name="name">
<p> 연락처 : <select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="018">018</option>
</select> -
<input type="text" maxlength="4" size="4" name="phone2"> -
<input type="text" maxlength="4" size="4" name="phone3">
<p> 성별 : <input type="radio" name="gender" value="남성" >남성
<input type="radio" name="gender" value="여성" checked>여성
<p> 취미 : 독서<input type="checkbox" name="hobby" value="독서" checked>
운동<input type="checkbox" name="hobby" value="운동">
영화<input type="checkbox" name="hobby" value="영화">
<p> <textarea name="comment" cols="30" rows="3" placeholder="가입 인사를 입력해주세요"></textarea>
<p> <input type="submit" value="가입하기">
<input type="reset" value="다시쓰기">
</form>
</body>
</html>
<%@ 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>
<%
String id = (String)request.getAttribute("id");
String passwd = (String)request.getAttribute("passwd");
String name = (String)request.getAttribute("name");
String phone1 = (String)request.getAttribute("phone1");
String phone2 = (String)request.getAttribute("phone2");
String phone3 = (String)request.getAttribute("phone3");
String gender = (String)request.getAttribute("gender");
String[] hobby = (String[])request.getAttribute("hobby");
String comment = (String)request.getAttribute("comment");
%>
<p> 아이디 : <%=id %>
<p> 비밀번호 : <%=passwd %>
<p> 이름 : <%=name %>
<p> 연락처 : <%=phone1 %>-<%=phone2 %>-<%=phone3 %>
<p> 성별 : <%=gender %>
<p> 취미 : <%
if (hobby != null) {
for (int i=0; i < hobby.length; i++) {
out.println(" " + hobby[i]);
}
}
%>
<p> 가입 인사 : <%=comment %>
</body>
</html>
<%@ 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>
<h3>회원가입</h3>
<form action="form02" name="member" method="get">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복 검사">
<p> 비밀번호 : <input type="password" name="passwd">
<p> 이름 : <input type="text" name="name">
<p> 연락처 : <select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="018">018</option>
</select> -
<input type="text" maxlength="4" size="4" name="phone2"> -
<input type="text" maxlength="4" size="4" name="phone3">
<p> 성별 : <input type="radio" name="gender" value="남성" >남성
<input type="radio" name="gender" value="여성" checked>여성
<p> 취미 : 독서<input type="checkbox" name="hobby1" value="독서" checked>
운동<input type="checkbox" name="hobby2" value="운동">
영화<input type="checkbox" name="hobby3" value="영화">
<p> <textarea name="comment" cols="30" rows="3" placeholder="가입 인사를 입력해주세요"></textarea>
<p> <input type="submit" name="가입하기">
<input type="reset" name="다시쓰기">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*, java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<tr>
<th>요청 파라미터 이름</th>
<th>요청 파라미터 값</th>
</tr>
<%
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String name = (String) paramNames.nextElement();
out.print("<tr><td>" + name + "</td>\n");
String paramValue = request.getParameter(name);
out.print("<td>" + paramValue + "</td></tr>\n");
}
%>
</table>
</body>
</html>