본문 바로가기
Spring

[Spring] web.xml 설명

by BENGGRI 2021. 1. 18.
반응형

web.xml

Deployment Descriptor (배포 서술자)

 

 

<web-app>

web.xml 의 Root-Element 기능을 담당

<web-app 
    version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                        https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
</web-app>

<display-name>

web.xml(DD) 의 Title 설정, 기본적으로 프로젝트명을 설정

<display-name>project_name</display-name>

<welcome-file-list>

서버로 요청이 들어왔을 때 표시할 welcome-file 을 순서대로 정의

없을 경우 404 페이지 호출

<welcome-file-list>
	<welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

<error-page>

error code, exception type 을 error page 로 매핑

<error-page>
	<error-code>404</error-code>
    <location>/error/404.jsp</location>
</error-page>
<error-page>
	<exception-type>java.lang.NullPointException</exception-type>
    <location>/error/404.jsp</location>
</error-page>

<context-param>

Servlet context 의 parameter 선언

<context-param>
	<param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<listener>

Application Listener Bean 을 지정

(Bean 은 웹 어플리케이션에 등록 필수)

<listener>
	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<filter>

웹 어플리케이션에서 사용하는 filter 설정

( 대표적으로 encodingFilter )

<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>

<fileter-mapping>

<filter> 에서 어떤 filter 를 사용할지 설정한 후

<filter> 에서 설정한 filter어디에 적용할 것인지 설정

<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>

Servlet 을 설정

( 대표적으로 DispatcherServlet )

<servlet>
	<servlet-name>appServlet</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	<init-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
	</init-param>
	<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>

Servlet 과 URL 사이의 매핑을 설정

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

 

 

 

 

 

 

 

 

반응형

댓글