-
JSP 내장 객체 (3) - Application 내장 객체웹 Web/JSP & Servlet 2022. 1. 24. 21:38
p.203
컨텍스트 이름 혹은 프로젝트 내 JSP파일의 경로를 알고싶을 때 사용하는 메소드
getServerInfo() : 컨테이너의 이름과 버전 반환
getContextInfo() : 웹 애플리케이션의 URL경로 중 컨텍스트 패스명을 반환
getRealPath() : JSP의 실제 경로 반환
getMimeType(finename) : 지정된 파일의 MIME 탕비을 반환
log(message) : 지정된 message의 로그를 저장
p.204
내장객체의 영역
page: 하나의 JSP페이지를 처리할 때 사용되는 영역
request: 하나의 요청을 처리할 때 사용되는 영역
session: 하나의 브라우저와 관련된 영역
application: 하나의 웹 애플리케이션과 관련된 영역
<07_firstPage.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% pageContext.setAttribute("name", "page man"); request.setAttribute("name", "request man"); session.setAttribute("name", "session man"); applicaton.setAttribute("name", "application man"); System.out.println("firstPage.jsp"); System.out.println("하나의 페이지 속성: " + pageContext.getAttribute("name")); System.out.println("하나의 요청 속성: " + request.getAttribute("name")); System.out.println("하나의 세션 속성: " + session.getAttribute("name")); System.out.println("하나의 애플리케이션 속성: " + application.getAttribute("name")); request.getRequestDispatcher("07_secondPage.jsp").forward(request, response); %> </body> </html>
firstPage.jsp:
하나의 페이지 속성: page man
하나의 요청 속성: request man
하나의 세션 속성: session man
하나의 애플리케이션 속성: application manfirstPage에서 secondPage로 포워드 방식을 사용해 이동
<07_secondPage.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> 하나의 페이지 속성: <%= pageContext.getAttribute("name") %> <br> 하나의 요청 속성: <%= request.getAttribute("name") %> <br> 하나의 세션 속성: <%= session.getAttribute("name") %> <br> 하나의 애플리케이션 속성: <%= application.getAttribute("name") %> <br> </body> </html>
하나의 페이지 속성: null
하나의 요청 속성: request man
하나의 세션 속성: session man
하나의 어플리케이션 속성: application mansecondPage에서 thirdPage로 redirect방식을 사용해 이동
<07_thirdPage.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% pageContext.setAttribute("name","page man"); request.setAttribute("name","request man"); session.setAttribute("name","session man"); application.setAttribute("name","application man"); System.out.println("firstPage.jsp: "); System.out.println("하나의 페이지 속성: " + pageContext.getAttribute("name")); System.out.println("하나의 요청 속성: " + request.getAttribute("name")); System.out.println("하나의 세션 속성: " + session.getAttribute("name")); System.out.println("하나의 애플리케이션 속성: " + application.getAttribute("name")); request.getRequestDispatcher("47_secondPage.jsp").forward(request, response); %> </body> </html>
하나의 페이지 속성: null
하나의 요청 속성: null
하나의 세션 속성: session man
하나의 어플리케이션 속성: application man'웹 Web > JSP & Servlet' 카테고리의 다른 글
하나의 Servlet에서 여러 작업을 수행하기 - CRUD (0) 2023.02.08 Servlet과 JSP간 데이터 전달 - RequestDispatcher (0) 2023.02.07 JSP 내장 객체 (2) - forward (0) 2022.01.17 JSP 내장 객체 (1) - JSP로 설문조사폼(sendRedirect..) (0) 2022.01.17 JSP 내장객체 (0) - JSP로 설문조사폼 (0) 2022.01.17