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

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

양심고백 2024. 4. 14. 23:13
반응형

쉽게 배우는 JSP 웹 프로그래밍 (송미영 저)

 

 

 

[ 6장 연습문제 P.231 ~ P.234 ]

1. 폼을 구성하는 태그의 종류로 옳지 않은 것은 무엇인가?

정답: textarea: 한 줄을 입력할 수 있는 태그이다.

 

 

2. form 태그의 속성으로 옳지 않은 것은 무엇인가?

정답: ③ name: 폼을 식별하기 위한 이름으로 중복으로 설정할 수 있다.

 

 

3. input 태그의 type 속성 값으로 옳지 않은 것은 무엇인가?

정답: ④ checkbox: 체크박스로 열거된 것 중 하나만 선택할 때 사용한다.

 

 

4. input 태그의 type 속성 값 중에서 보이지 않게 숨겨서 값을 전송할 때 사용하는 속성 값은 무엇인가? 

정답:  hidden

 

 

5. 다음 중 단일 요청 파라미터의 값을 받는 메소드는 무엇인가?

정답: ① request.getParameter( )

 

 

6. 다음은 폼 페이지에서 회원 가입 양식에 연락처를 입력하는 프로그램이다. 이프로그램의 밑줄에 들어갈 올바른 것은 무엇인가?

<form action = "#" method="get">
	<p> 연락처 : <_________name="phone1">
    	<option value="02">02</option>
        <option value="031">031</option>
        <option value="032">032</option>
        </__________> - <input type="text" maxlength="4" size="4" name="phone2"> 
        - <input type="text" maxlength="4" size="4" name="phone3">
</form>

정답: ② select

 

 

7. 다음은 폼 페이지에서 여러 줄의 텍스트를 입력할 수 있도록 작성한 것이다. 프로그램의 밑줄에 들어갈 올바른것은 무엇인가?

<form action="#" method="get">
	<____________ name="comment" cols="30" rows="3"></____________>
    <p> <input type="submit" value="전송" />
    <input type="reset" value="취소" />
</form>

정답: ① textarea

 

 

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

form01.jsp 코드

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
	<form action="form01_process.jsp" 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 language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<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>

 

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

form02.jsp 코드

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
	<form action="form02_process.jsp" 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 name = new StringBuffer((String) paramNames.nextElement());
			out.print(name + " : " + "\n");
			
			String paramValue = request.getParameter(name.toString());
			out.println(paramValue + "<br>");
		}
	%>
</body>
</html>

 

 

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

form03.jsp 코드

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

 

form03_process.jsp

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

 

 

※ 직접 풀이를 진행하였기 때문에 오류가 있을 수 있습니다.

오류를 발견 시, 댓글로 남겨주시면 감사하겠습니다..!

반응형