Problem solving/쉽게 배우는 JSP 웹 프로그래밍

[쉽게 배우는 JSP 웹 프로그래밍] 6장 연습문제

공부좀하시졍 2020. 10. 21. 03:12

1. form 태그에 사용하는 속성에 대해 간단히 설명하시오.

폼 데이터를 받아 처리하는 웹페이지의 URL을 설정하는 action 속성

폼 데이터가 전송되는 HTTP 방식을 설정하는 method 속성

폼을 식별하기 위한 이름을 설정하는 name 속성

폼 처리 결과의 응답을 실행할 프레임을 설정하는 target 속성

폼을 전송하는 콘텐츠 MIME 유형을 설정하는 enctype 속성

폼 전송에 사용할 문자 인코딩을 설정하는 accept-charset 속성이 있다.

 

2. form 태그 내에 중첩하여 사용하는 태그를 나열하고 설명하시오.

input 태그, select 태그, textarea 태그가 있다.

input 태그는 사용자가 텍스트 입력이나 선택 등을 다양하게 할 수 있도록 공간을 만드는 태그이다.

select 태그는 여러 개의 항목이 나타나는 목록 상자에서 항목을 선택하는 태그이다. 리스트 박스에 여러 항목을 추가 삽입하기 위해 반드시 option 태그를 포함해야 한다.

textarea 태그는 여러 줄의 텍스트를 입력할 수 있는 태그이다.

 

3. 폼 페이지에서 전송된 데이터를 전달받는 내장 객체와 관련된 메소드는 무엇인가?

request 내장 객체 / getParameter() 메소드

 

4. form 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.

form01.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
	<form action="form01_process.jsp" name="member" method="post">
		<p> 이름: <input type="text" name="name">
		<p> 주소 : <input type="text" name="address">
		<p> 이메일 : <input type="text" name="email">
		<p> <input type="submit" value="전송">
	</form>
</body>
</html>

form01_process.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
	<%
		request.setCharacterEncoding("UTF-8");

		StringBuffer name = new StringBuffer();
		StringBuffer address = new StringBuffer();
		StringBuffer email = new StringBuffer();
		
		name.append(request.getParameter("name"));
		address.append(request.getParameter("address"));
		email.append(request.getParameter("email"));
	%>
	
	<p> 이름 : <%=name.toString() %>
	<p> 주소 : <%=address.toString() %>
	<p> 이메일 : <%=email.toString() %>
	
</body>
</html>

 

5. form 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.

form02.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
	<form action="form02_process.jsp" name="member" method="post">
		<p> 이름: <input type="text" name="name">
		<p> 주소 : <input type="text" name="address">
		<p> 이메일 : <input type="text" name="email">
		<p> <input type="submit" value="전송">
	</form>
</body>
</html>

form02_process.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.util.*, java.io.*" %>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
	<%
		request.setCharacterEncoding("UTF-8");
		
		Enumeration paramNames = request.getParameterNames();
		while (paramNames.hasMoreElements()) {
			StringBuffer info = new StringBuffer((String) paramNames.nextElement());
			out.print("<b>" + info + "</b> " + " : " + "\n");
			
			String infoValue = request.getParameter(info.toString());
			out.println(infoValue + "<br>");
		}
	%>
</body>
</html>

 

6. form 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.

form03.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
	<form action= "form03_process.jsp" name="fruit" method="post">
		<p> 오렌지 <input type="checkbox" name="fruit" value="Orange" checked>
			사과 <input type="checkbox" name="fruit" value="Apple" >
			바나나 <input type="checkbox" name="fruit" value="Banana" checked>
			<input type="submit" value="전송" >
		</p>
	</form>
</body>
</html>

form03_process.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
	<%
		request.setCharacterEncoding("UTF-8");
		String[] fruit= request.getParameterValues("fruit");
	%>
	<p><b>선택한 과일</b></p>
	<br>
	<%
		if(fruit != null) {
			for (int i = 0;i < fruit.length;i++) {
				out.println("<b>" + " " + fruit[i] + "</b>");
			}
		}
	%>
</body>
</html>

2020/10/21 - [Problem solving/쉽게 배우는 JSP 웹 프로그래밍] - [쉽게 배우는 JSP 웹프로그래밍] 5장 연습문제