web.xml
web.xml 파일은 Java 웹 애플리케이션의 **배포 서술자(deployment descriptor)**로, 웹 애플리케이션의 동작 방식과 구성 요소들을 정의합니다. 각 항목을 순서대로 설명드릴게요:
📌 루트 엘리먼트
<web-app xmlns=... version="2.5">
- Servlet 버전 2.5 기반의 웹 애플리케이션임을 나타냅니다.
- XML 네임스페이스를 지정하여 문법 검증이 가능하도록 설정합니다.
📛 display-name
<display-name>egov.sample</display-name>
- 웹 애플리케이션의 이름입니다. (관리 콘솔 등에서 표시용)
🔤 Filter 설정
1. CharacterEncodingFilter (한글 깨짐 방지)
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
- 모든 .do 요청에 대해 UTF-8 인코딩을 적용합니다.
- 주로 POST 방식에서 한글 깨짐을 방지하기 위해 사용합니다.
2. HTMLTagFilter (보안 필터)
<filter>
<filter-name>HTMLTagFilter</filter-name>
<filter-class>egovframework.rte.ptl.mvc.filter.HTMLTagFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HTMLTagFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
- <script>, <iframe>등 HTML 태그를 필터링하여 XSS 공격을 방지합니다.
- eGovFrame에서 제공하는 보안 필터입니다.
⚙️ Spring 설정
context-param + ContextLoaderListener
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:egovframework/spring/context-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
- Spring의 루트 ApplicationContext를 초기화합니다.
- 지정된 context-.xml 파일들을 로딩하여 Bean 설정 정보를 읽어옵니다.
🚦 DispatcherServlet 등록 (Spring MVC 중심 컨트롤러)
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/egovframework/springmvc/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
- Spring MVC의 핵심 컨트롤러인 DispatcherServlet을 등록합니다.
- .do로 끝나는 URL 요청은 모두 이 서블릿이 처리합니다.
- 서블릿 초기화 시 별도의 Spring 설정 파일(dispatcher-servlet.xml)을 사용합니다.
🏠 Welcome 파일 설정
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
- 웹 애플리케이션 접속 시 기본으로 보여줄 파일 (예: http://localhost:8080/ → index.jsp)
🔐 로그인 설정
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
- HTTP Basic 인증 사용 설정 (보통 개발용 또는 단순한 인증 용도)
🚨 에러 페이지 설정
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/common/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/common/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/common/error.jsp</location>
</error-page>
- 예외 발생 시 /common/error.jsp로 이동
- 404(페이지 없음), 500(서버 오류)도 동일한 에러 페이지를 사용
✅ 요약
항목 | 설명 |
---|---|
필터 | 인코딩 설정, HTML 태그 필터링(XSS 방지) |
컨텍스트 설정 | Spring Bean 설정을 로딩 |
서블릿 | DispatcherServlet을 등록하여 MVC 구조 처리 |
인증 | BASIC 인증 사용 설정 |
에러 처리 | 예외 및 HTTP 오류에 대한 에러 페이지 지정 |
이 설정은 전자정부프레임워크(eGovFrame) 기반의 Spring MVC 애플리케이션에서 자주 사용하는 전형적인 web.xml 구성입니다.
'전자정부 프레임워크 공부' 카테고리의 다른 글
전자정부 프레임워크 3.10 - selectSampleList (0) | 2025.05.19 |
---|---|
전자정부 프레임워크 3.10 - index.jsp (0) | 2025.05.19 |
게시판 페이지네이션 기능 구현 [전자정부 프레임워크 공부] (0) | 2025.05.18 |
게시판 개발용 페이크 데이터 추가하기 [전자정부 프레임워크 공부] (0) | 2025.05.18 |
Dynamic Web Project 게시판 예제 [전자정부 프레임워크 공부] (0) | 2025.05.18 |