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

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

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

1. 폼 페이지에서 입력된 데이터를 전달하는 요청 파라미터 값을 JSP 페이지로 가져오는 내장 객체는 무엇인지, 그리고 관련된 메소드에 대해 간단히 설명하시오.

request 내장 객체 이다. 

요청 파라미터 이름이 name인 값을 전달 받는 getParameter(String name)

모든 요청 파라미터 이름이 name인 값을 배열 형태로 전달받는 getParameterValues(String name)

모든 요청 파라미터의 이름과 값을 Enumeration 객체 타입으로 전달 받는 getParameterNames() 등이 있다.

 

2. 서버에서 웹 브라우저에 다른 페이지로 강제 이동하도록 명령하는 내장 객체와 관련된 메소드는 무엇인가?

response 내장 객체의 sendRedict() 메소드 이다.

 

3. 스크립트 태그의 표현문과 같이 데이터를 출력하는 내장 객체는 무엇인가?

out 내장 객체 이다.

 

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

request.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
	<form action="request_process.jsp" method="get">
		<p> 아 이 디 : <input type="text" name="id"></p>
		<p> 비밀번호 : <input type="text" name="passwd"></p>
		<p> <input type="submit" value="전송" />	
	</form>
</body>
</html>

request_process.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
	<%
		String info = request.getQueryString();
	%>
	<p>전송된 요청 파라미터 : <b><%=info %></b>
</body>
</html>

 

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

response.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.util.Calendar" %>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
	<%
		response.setHeader("Refresh","5");
		Calendar cal = Calendar.getInstance();
		String am_pm;
		int hour = cal.get(Calendar.HOUR_OF_DAY);
		int minute = cal.get(Calendar.MINUTE);
		int second = cal.get(Calendar.SECOND);
		
		if (hour < 12)
			am_pm = " AM";
		else {
			am_pm = " PM";
			hour = hour - 12;
		}
		String CT = hour + ":" + minute + ":" + second + am_pm;
	%>
	<p>현재 시간은 <b><%=CT %></b>
	<p> <a href="./response_data.jsp"><U>Google 홈페이지로 이동하기</U></a>
</body>
</html>

response_data.jsp

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
	<%
		response.sendRedirect("http://www.google.com");
	%>
</body>
</html>

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