Cute Happy Ghost
본문 바로가기
JAVA/Java

web.xml의 element(context-param,filter)

by JENN_tech7 2022. 8. 9.
728x90
SMALL

<welcome-file-list> 

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

index.jsp가 없다면 index2.jsp로 넘어감

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

 

 

 

<error-page>

error code 혹은 exception type을 error page로 매핑하기 위한 부분

  • error-code: 웹의 에러 코드를 적어주는 변수
  • exception-type: java exception type을 적어주는 변수
  • location: 매핑할 페이지의 경로를 적는 변수
<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error/404</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/error/404</location>
</error-page>

 

 

 

 

<context-param> 

Servlet context의 parameter를 선언해주는 부분

  • param-name: context parameter의 이름
  • param-value: context parameter의 값

기본)

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

 

응용)

용도에 따라 contex-*.xml별로 나눠서 하고있기때문에

context-*.xml에 해당하는 모든 파일들을 parameter로 넣을 수 있다

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:config/spring/context-*.xml
    </param-value>
</context-param>

 

 

<filter>

웹 애플리케이션에서 사용하는 filter를 선언하는 부분이다.
어떤 filter를 사용할 것인지 설정하는 부분으로, 대표적으로 encodingFilter가 있다.

  • filter-name: Required, unique, filter-mapping Element와 매핑하기 위한 변수
  • filter-class: 사용할 클래스의 정규화 된 이름을 나타내는 변수
  • init-param: filter에서 사용할 name-value 쌍을 선언하는 부분
<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-mapping Element는 설정한 filter를 어디에 적용할 것인지를
URL 또는 Servlet을 통해 선언하는 부분이다.

  • filter-name: filter Element와 매핑하기 위한 변수
  • url-pattern: filter를 적용할 url을 선언하는 부분
  • servlet-name: filter를 적용할 servlet을 선언하는 부분
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
728x90
LIST

댓글