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

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

양심고백 2024. 3. 31. 00:00
반응형

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

 

[ 4장 연습문제 P.159 ~ P.162 ]

1. 다음 중 액션 태그에 대한 설명으로 옳지 않은 것은 무엇인가?

정답: <%...%>와 같은 스크립트 태그의 형식을 따른다.

 

 

2. forward 액션 태그에 대한 설명으로 옳지 않은 것은 무엇인가?

정답: ② 이전 페이지 및 이동 페이지의 모든 내용을 출력한다.

 

 

3. include 액션 태그에 대한 설명으로 옳지 않은 것은 무엇인가?

정답: ③ 정적 페이지에 사용한다.

 

 

4. 자바빈즈를 작성할 때 따라야 할 규칙이 아닌 것은 무엇인가?

정답: ① 자바 클래스는 java.io.Serializable 인터페이스를 반드시 구현해야 한다.

 

 

5. 자바빈즈에 사용하는 액션 태그로 옳지 않은 것은 무엇인가?

정답: setBean 액션 태그

 

 

6. 다음은 include 액션 태그에서 second.jsp 파일로 매개변수 date 값을 전송하는 프로그램의 밑줄에 들어갈 올바른 것은 무엇인가?

<jsp:include page="second.jsp">
	<jsp:____________ name="date" value="<%=new java.util.Date() %>" />
</jsp:include>

정답: ① param

 

 

7. 다음 프로그램의 밑줄에 들어갈올바른 것은 무엇인가? 

<jsp:____________ id="date" class="java.util.Date" />
<%
	out.print("오늘의 날짜 및 시각" +date );
%>

정답: ② useBean

 

 

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

forward.jsp 코드

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Action Tag</title>
</head>
<body>
	<h4>구구단 출력하기</h4>
	<jsp:forward page="forward_data.jsp">
		<jsp:param value="5" name="number"/>
	</jsp:forward>
</body>
</html>

 

forward_data.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Action Tag</title>
</head>
<body>
	<%
		int num = Integer.parseInt(request.getParameter("number"));
		for(int i=1; i<10; i++){
			int result = num*i;
			out.print(num +" * "+i+" ="+result+"<br>");
		}
	%>
</body>
</html>

 

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

include.jsp 코드

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Action Tag</title>
</head>
<body>
	<h4>구구단 출력하기</h4>
	<jsp:include page="include_data.jsp">
		<jsp:param value="5" name="number"/>
	</jsp:include>
</body>
</html>

 

include_data.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Action Tag</title>
</head>
<body>
	<%
		int num = Integer.parseInt(request.getParameter("number"));
		for(int i=1; i<10; i++){
			int result = num*i;
			out.print(num +" * "+i+" ="+result+"<br>");
		}
	%>
</body>
</html>

 

 

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

GuGuDan.java

package ch04.com.dao;

public class GuGuDan {
	public String process(int n) {
		String result = "";
		for(int i=1; i<10; i++){
			result += n + " * " + i + " = " + (n * i) + "<br>";
		}
		return result;
	}
}

 

useBean.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Action Tag</title>
</head>
<body>
	<h4>구구단 출력하기</h4>
	<jsp:useBean id="bean" class="ch04.com.dao.GuGuDan" />
	<%
		out.println(bean.process(5));
	%>
</body>
</html>

 

 

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

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

반응형