web.xml 이란 ? 

web.xml이란 webapplication의 deployment Descriptor로서 xml형식의 파일이다. 

모든 web application은 반드시 web.xml파일을 가진다.

web-inf폴더의 하위를 보면 이 xml파일을 찾을 수 있고, 내부에설정된 내용은

web application시작 시 메모리에 로딩된다. 

 

[브라우저]가 [java servlet]에 접근하기 위해 was(tomcat)에 필요한 정보를 알려줘야 

해당하는 servlet을 호출할 수 있고 이것을 정하는 곳이 web.xml이다

 

매우 중요한 부분이지용 ?


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" 
 id="WebApp_ID" version="4.0">
  <display-name>onbiz</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>
  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <async-supported>true</async-supported>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <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>/*</url-pattern>
  </filter-mapping>
  <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/views/error/error404.jsp</location>
  </error-page>
  <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>
  <session-config>
  	<session-timeout>10</session-timeout>
  </session-config>
</web-app>

 

web.xml 의 역할은 무엇이있을까?

Diaspatcher-servlet : 클라이언트의 요청을 가로채어 컨트롤러에 보낸다( 클라이언트 요청을 최초로 받는 클래스)

contextLoarderListner

encodingFilter 

 

이렇게 세가지가 있다. 


1. welcome-file-list : 웰컴 파일이란 디렉토리의 기본 웹 페이지이다.

클라이언트가 서블릿 이름을 생략하고 디렉토리까지만 지정해서 요청한다면 웹 서버는 해당 디렉토리에서 웰컴 파일을 찾아서 응답한다. 여러 개의 웰컴 파일이 있으면 위에서부터 아래로 순차적으로 조회하고 먼저 찾은 것을 클라이언트에게 보낸다. <welcome-file-list>태그 안에 순서대로 작성한다. 

 

2. filter 

인코딩을 UTF-8로 설정하여 필터링하겠다는 설정이다.
https://gmlwjd9405.github.io/2018/10/29/web-application-structure.html

3. errorpage 

에러가 생겼을 경우 location을 설정하여 사용자가 정의한 인터페이스로 에러를 보여주는 것을 설정한다.

4. listner

 

[서블릿/JSP] 리스너(Listner)란? 이벤트 리스너의 개념 설명. 구현 및 등록하기

리스너란? 이벤트, 리스너, 이벤트핸들러 간략 개념정리 리스너는 단어의 뜻으로 보자면 (소리를) 듣는 사람, 청취자입니다. 프로그래밍에서의 리스너는 무언가 소리를 듣는 사람을 뜻하기 보다

dololak.tistory.com

이해한 바로 요약해보자면, 클라이언트가 요청한 내용을 객체에 담아 가져오도록 하기 위해 리스너를 설정한다.

스프링에서 현재 HttpServletRequest 가져오는 방법

  • 이벤트 - 발생한 특정 사건(마우스 클릭, 키보드 입력, 클라이언트로부터의 HTTP 요청, 웹어플리케이션 시작, 웹어플리케이션 종료 등)
  • 이벤트 소스 - 이벤트가 발생한 대상(근원지)으로 마우스, 키보드, 웹어플리케이션(ServletContext) 등
  • 리스너, 핸들러 - 이벤트가 발생되기를 기다렸다가 발생시 실행되는 메서드나 함수. 또는 메서드를 가진 객체



출처: https://dololak.tistory.com/616 [코끼리를 냉장고에 넣는 방법]

 

5. session-config

세션유지시간을 설정하며 단위는 분이다. <session-timeout> 태그 사이에 작성한다. 

+ Recent posts