특정 웹 어플리케이션에 포함된 모든 JSP 페이지는 하나의 application 기본 개체를 공유하게 된다.
초기 설정 정보를 읽어올 수 있으며 / 서버 정보를 읽어올 수 있고 / 제공파는 자원(파일)을 읽어올 수 도 있다.
<context-param>
<param-name>파라미터 이름</param-name>
<param-value>파라미터 값</param-value>
</context-param>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>07_21</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<description>로깅 여부</description>
<param-name>logEnabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>디버깅 레벨</description>
<param-name>debugLevel</param-name>
<param-value>5</param-value>
</context-param>
</web-app>
<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>초기화 파라미터 읽어오기</title>
</head>
<body>
초기화 파라미터 목록:
<ul>
<%
Enumeration<String> initParamEnum = application.getInitParameterNames();
while(initParamEnum.hasMoreElements()) {
String initParamName = initParamEnum.nextElement();
%>
<li><%= initParamName %> =
<%= application.getInitParameter(initParamName) %>
<%
}
%>
</ul>
</body>
</html>

출력 결과
웹 어플리케이션 초기화 파라미터는 이름처럼 웹 어플리케이션을 초기화하는 데 필요한 설정 정보를 지정하기 위해 사용된다. 예를 들어, 데이터베이스 연결과 관련된 설정 파일의 경로나, 로깅 설정 파일, 또는 웹 어플리케이션의 주요 속성 정보를 담고 있는 파일의 경로 등을 지정할 때 초기화 파라미터를 사용한다. → 여러 JSP에서 사용되는 값들을 넣어서 사용한다.
메이저 버전은 소수점 위에 숫자
마이너 버전은 소수점 아래 숫자
웹 컨테이너가 사용하는 로그 파일에 로그 메세지를 기록할 수 있도록 메서드를 제공한다.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>application 기본 객체 사용하여 자원 읽기</title>
</head>
<body>
<%
String resourcePath = "/message/notice.txt";
%>
자원의 실제 경로:<br>
<%= application.getRealPath(resourcePath) %>
<br>
--------------<br>
<%= resourcePath %>의 내용<br>
--------------<br>
<%
char[] buff = new char[128];
int len = -1;
InputStreamReader isr = null;
InputStream is = application.getResourceAsStream(resourcePath);
try {
isr = new InputStreamReader(is);
while( (len = isr.read(buff)) != -1) {
out.print(new String(buff, 0, len));
}
} catch(IOException e) {
e.printStackTrace();
} finally {
try {
isr.close();
} catch(Exception e) {}
try {
is.close();
} catch(Exception e) {}
}
/*
try(InputStreamReader br = new InputStreamReader(application.getResourceAsStream(resourcePath))) {
while( (len = br.read(buff)) != -1) {
out.print(new String(buff, 0, len));
}
} catch(IOException e) {
out.println("익셉션 발생 :" + e.getMessage());
}
*/
%>
</body>
</html>

실행결과
C:\Users\GG\Desktop\Java\source code.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\07_21\data
web.xml에 파일에 추가하기
path /data/docList.dat각 JSP 파일들마다 파일경로로 설정한다. 저장할 경로가 바뀌면 web.xml에서 경로만 바꿔주면 된다.
String path = application.getInitParameter("path");
속성은 <속성이름, 값>의 형태를 갖는다.
Map 형식으로 key는 String, value는 object를 갖는다.
