config 내장 객체는 JSP 페이지가 서블릿 클래스로 변환되어
서블릿 인스턴스가 생성될 때 참조해야 할 초기 설정 정보들을 저장해 놓은 객체이다.
이러한 초기 설정 정보들은 웹 컨테이너가 구동될 때 자체적으로 생성/관리되며
서블릿 당 1개만의 객체가 생성되며 같은 서블릿 인스턴스는 동일한 config 객체를 참조하게 된다.
실행방법 : 1. 이클립스 Servers 뷰에서 start 선택
2. 브라우저에서
http://localhost:8088/JspProject/configTest
입력합니다.
web.xml 하단에 추가 wep-app 내부에 존재
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<servlet>
<servlet-name>configTest1</servlet-name>
<!--프로젝트명 이후의 경로를 적습니다. -->
<!--해당 서블릿에서 초기화 파라미터를 설정한 부분입니다.-->
<init-param>
<param-name>이름</param-name><!-- 초기화 파라미터의 이름입니다.-->
<param-value>사랑이</param-value> <!-- 초기화 파라미터의 값입니다.-->
</init-param>
<init-param>
<param-name>나이</param-name><!-- 초기화 파라미터의 이름입니다.-->
<param-value>20세</param-value> <!-- 초기화 파라미터의 값입니다.-->
</init-param>
</servlet>
<servlet-mapping>
<!---->
<servlet-name>configTest1</servlet-name>
<url-pattern>/configTest</url-pattern>
</servlet-mapping>
Colored by Color Scripter
|
위와 같은 방법으로 email값도 추가해보세요
configTest1.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>config</title>
</head>
<body>
<table>
<caption>Config 테스트</caption>
<tr>
<td>초기 파라미터 이름</td>
<td>초기 파라미터 값</td>
</tr>
<tr>
<td>이름</td>
<td><%=config.getInitParameter("이름")%></td>
</tr>
<tr>
<td>나이</td>
<td><%=config.getInitParameter("나이")%></td>
</tr>
<tr>
<td>email</td>
<td><%=config.getInitParameter("email")%></td>
</tr>
</table>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
====결과====
'IT > JSP' 카테고리의 다른 글
web.xml로 url 제어하기 (0) | 2019.05.13 |
---|---|
Config vs application (0) | 2019.05.13 |
jsp만 이용해서 로그인처리하기 (0) | 2019.05.13 |
application을 이용해 파라미터 이름과 값 불러오기 (0) | 2019.05.13 |
web.xml 설정 (0) | 2019.05.13 |