quilt code

[JSP] 05장 내장 객체 본문

daily/웹프로그래밍

[JSP] 05장 내장 객체

김뱅쇼 2023. 3. 23. 20:25

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


request 내장 객체
형식: <name=value>, 웹 브라우저에서 서버의 JSP 페이지로 전송
관련 메소드 종류:
1) getParameter(String name) - 요청 파라미터 이름이 name인 값을 전달받음. 요청 파라미터 값이 없으면  null 반환
2) getParameterValues(String name) - 모든 요청 파라미터 이름이 name인 값을 배열 형태로 전달 받음. 요청 파라미터 값이 없으면 null로 반환
3) getParameterNames() - 모든 요청 파라미터의 이름과 값을  Enumeration 객체 타입으로 전달받음.
4) getParameterMap() - 모든 요청 파라미터의 이름과 값을 Map 객체 타입으로 전달받음 

 


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


response 내장 객체의 sendRedirect(String url)   

 


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


out 내장 객체

 


4. request 내장 객체를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 어쩌구 

1) request.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
<%@ 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>
cs




2) request_process.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
<%@ 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>
cs

실행 결과)






 


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


1) response.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
<p> 현재 시간은 <%=java.util.Calendar.getInstance().getTime()%>
 
    <%
        response.setIntHeader("Refresh",5);
    %>
<p> <a href="./response_data.jsp"> Google 홈페이지로 이동하기</a>
</body>
</html>
 
cs


2) response_data.jsp

1
2
3
4
5
6
7
8
9
10
11
12
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>Implicit Objects</title>
</head>
<body>
    <%
        response.sendRedirect("http://www.google.com");
    %>
</body>
</html>
 
cs


실행결과)