다음 이전 차례

7. Web Application,war,web.xml

이 부분은 Java Servlet Specification Version 2.2 를 참조하였다. 이 장에 소개된 내용외는 이 문서를 참조하기 바란다.

Web Application 이란 Servlet,JSP,HTML문서,기타 이미지나 압축된 자료 및 다른 데이타를 포함하는 Web 관련 리소스이다.

이러한 Web Application 을 압축하여 배포하기 위한 파일이 WAR 파일이다. WAR 파일은 Web Application Archive이며 디렉토리를 포함하여 압축 혹은 패키지된 하나의 파일이다.

web.xml은 Deployment Descriptor 이며 XML 을 알고 있는 분은 $TOMCAT_HOME/conf/web.dtd를 보기 바란다. web.xml의 요소는 deployment 정보 및 환경 설정 등이며 다음과 같다.

web.xml 파일은 $TOMCAT_HOME/webapps/user_app/WEB-INF 디렉토리에 위치하며 user_app 디렉토리 이하에 있는 Web Application 의 환경 설정 부분을 담담한다고 보면 된다. 즉, 모든 Web Application 이 아닌 특정 Web Application 만의 환경 설정만을 하며, WAR 파일로 패키지 될 때 같이 포함된다.

WEB-INF 디렉토리에는 web.xml 파일과 classes 디렉토리 기타 lib 디렉토리가 위치한다. 참고로 classes 디렉토리에 servlet 과 utility class 등이 위치 할 수 있다.

참고로 web.xml은 각각의 사용자 디렉토리를 만든 후 해당 디렉토리에 대한 적절한 설정 후 $TOMCAT_HOME/conf/web.xml$TOMCAT_HOME/webapps/해당_디렉토리/WEB-INF/에 복사하여 사용한다. web.xml설정은 각자의 web application 에 맞게 설정한다.

다음은 web.dtd 및 web.xml의 간단한 설명과 예를 보이겠다. 또한 web.dtd 및 web.xml의 이해를 돕기 위해 xml 에 대한 간단한 설명을 하도록 하겠다.

다음은 $TOMCAT_HOME/conf/web.dtd 의 일부분이다.

<!--(주석) The session-timeout element defines the default session 
timeout interval for all sessions created in this web application. 
The specified timeout must be expressed in a whole number of minutes.-->
<!ELEMENT session-timeout (#PCDATA)>
<!ATTLIST session-timeout id ID #IMPLIED>
...........
...........
<!--(주석) The welcome-file-list contains an ordered list of 
welcome files elements. -->
<!ELEMENT welcome-file-list (welcome-file+)>
<!ATTLIST welcome-file-list id ID #IMPLIED>
<!--(주석) The welcome-file element contains file name to use 
as a default welcome file, such as index.html-->
<!ELEMENT welcome-file (#PCDATA)>
<!ATTLIST welcome-file id ID #IMPLIED>

위의 <!ELEMENT session-timeout (#PCDATA)> session 의 디폴트 Time-Out 시간을 설정하도록 하는 요소로서 요소 정의 부분이다. (#PCDATA)는 단말 노드를 의미하며 스트링이 오면 된다. (참고로 xml 은 트리 구조이다.)

<!ATTLIST session-timeout id ID #IMPLIED> 은 session-timeout 요소에 대한 속성의 정의 부분이다. #IMPLIED는 session-timeout 요소의 id 가 생략가능함을 의미한다. 즉, <session-timeout id="123dc56"> 처럼 되어야 하나 #IMPLIED 로 인해 <session-timeout> 가 되어도 된다.

welcome-file 은 web-application 의 welcome-file을 정의하며 아파치의 DocumentRoot의 index.html 과 같다고 보면 된다. (welcome-file+) 은 welcome-file-list 요소의 자식노드를 정의 하며 "+" welcome-file 요소가 하나 이상 있어도 된다는 의미이다. 아래의 web.xml 의 예의 welcome-file-list 요소내의 welcome-file요소들처럼 다수가 올 수 있다는 의미이다.

다음은 $TOMCAT_HOME/conf/web.xml의 일부분이다.

<session-timeout>
  30
</session-timeout>
..........
..........
<welcome-file-list>
<welcome-file>
   index.jsp
</welcome-file>
<welcome-file>
   index.html
</welcome-file>
<welcome-file>
   index.htm 
</welcome-file>
</welcome-file-list>


다음 이전 차례