써먹는 웹개발

[Jsp] web.xml 이란? 본문

웹개발/Java & Jsp

[Jsp] web.xml 이란?

kmhan 2018. 7. 9. 09:21


728x90
반응형

web.xml 이란


Web Application의 배포서술자로 XML형식의 파일입니다

모든 웹 어플리케이션은 하나 이상의 web.xml 파일을 가져야 하는데요

위치는 WEB-INF 폴더 아래 위치합니다


web.xml이 하는 역할을 다음과 같습니다

1. ServletContext의 초기 파라미터

2. Session의 유효시간 설정

3. Servlet/JSP에 대한 정의

4. Servlet/JSP 매핑

5. Mime Type 매핑

6. Welcome File list

7. Error Pages 처리

8. 리스너/필터 설정

9. 보안


만약에 web.xml이 수정되었다면 WAS를 재시작해야합니다

예를 들어 web.xml을 만들어 보겠습니다

이렇게 만들 수 있다는 예로서, 필요한 부분만 참고하면 될거같아요


<servlet> <-- 3. Servlet/JSP에 대한 정의-->

 <servlet-name> 객체의 이름</servlet-name>

 <servlet-class> 객체를 생성할 클래스 </servlet-class>

</servlet>

<servlet-mapping>

 <servlet-name> 객체의 이름 </servlet-name>

 <url-pattern>패턴</url-pattern> <!-- 4. Servlet/JSP 매핑 -->

</servlet-mapping> 

<!-- 2. Session의 유효시간 설정 세션 기간 설정 --> 

    <session-config>

      <session-timeout>

        30

      </session-timeout>

    </session-config>


    <!-- mime 매핑 --> 5. Mime Type 매핑

    <mime-mapping>

      <extension>txt</extension>

      <mime-type>text/plain</mime-type>

    </mime-mapping>


    <!-- 6. Welcome File list 시작페이지 설정 -->

    <welcome-file-list> 

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

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

    </welcome-file-list>


    <!-- 7. Error Pages 처리 존재하지 않는 페이지, 404에러시 처리 페이지 설정 -->

    <error-page> 

      <error-code>404</error-code>

      <location>/error.jsp</location>

    </error-page>


    <!-- 태그 라이브러리 설정 -->

    <taglib>

      <taglib-uri>taglibs</taglib-uri>

      <taglib-location>/WEB-INF/taglibs-cache.tld</taglib-location>

    </taglib>


    <!-- resource 설정 -->

    <resource-ref>

      <res-ref-name>jdbc/jack1972</res-ref-name>

      <res-type>javax.sql.DataSource</res-type>

      <res-auth>Container</res-auth>

    </resource-ref>

<!-- 1. ServletContext의 초기 파라미터 -->

<context-param>

      <param-name>breed</param-name>

      <param-value>Great Dane</param-value>

  </context-param>


<!-- 8. 필터설정 HTTP의 PUT 메소드를 사용하기 위해 필터 등록 -->

<!-- 이 필터 없을 시 서플릿이 Request Parameter를 처리하지 못함 -->

<filter>

    <filter-name>httpPutFormFilter</filter-name>

    <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>

</filter>


<!-- servlet-name으로 mapping -->

<filter-mapping>

    <filter-name>httpPutFormFilter</filter-name>

    <servlet-name>appServlet</servlet-name>

</filter-mapping>


<!-- 리스너 설정 Creates the Spring Container shared by all Servlets and Filters -->

<listener>

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

</listener>


 

[출처] web.xml 이란|작성자 티딩


728x90
반응형


Comments