태그 글목록: session timeout

[JSP & Servlet 배경지식] 4. Servlet – Deployment Descriptor(DD) 2014-09-19

> DD(Deployment Descriptor : 배포서술자)를 살펴보기 전에 자바 개발환경에서의 약속된 폴더구조를 알아보자.

>>> eclipse 개발환경에서의 폴더구조
eclipse_folder
>>>>>> description
① 서블릿파일들을 소스형태로 저장한다. 주로 비지니스로직을 구현한다.
② 서블릿파일들이 빌드되어 class형태로 자동 생성된다.
③ 사용자에게 보여지는 부분을 html로 구성한다.
④ 이번 포스팅에서 설명할 배포서술자가 위치하고 있으며 없어서는 안되는 파일이다.
⑤ 개발시 사용될 라이브러리들을 다운받아 추가하고 사용한다.
>>> Tomcat 서비스 환경에서의 폴더구조
service_folder
>>>>>> description
서비스 환경에서는 소스파일은 필요가 없고 빌드된 형태로 WEB-INF/Classes 폴더에 존재하게 된다.

> DD(Deployment Descriptor : 배포서술자)는 WEB-INF폴더 아래 web.xml이라는 파일명으로 항상 존재해야 하며 서버 시작시 메모리에 로딩된다. 클라이언트 요청에 대해 컨테이너는 DD를 참조하여 해당 서블릿에 맵핑시켜 준다. 또한 DD는 다음의 여러가지 환경정보를 설정할 수 있도록 한다.

- ServletContext 설정
- Session이 유지되는 시간 설정
- Servlet/JSP에 대한 정의
- Servlet/JSP 매핑
- Mime Type 매핑
- Welcome File list
- Error Pages 처리
- 리스너/필터 설정
- 보안설정 (에러처리)
>>> ServletContext & ServletConfig

– ServletContext : 어느 서블릿 객체에서든 접근 가능한 String을 저장한다. (READ or WRITE 가능)

<context-param>
   <param-name>propertiesPath</param-name>
   <param-value>/conf/global.properties</param-value>
</context-param>
ServletContext context = this.getServletContext();
String propertiesPath = context.getInitParameter("propertiesPath");

– ServletConfig : 특정 서블릿 객체에서만 접근 가능한 String을 저장한다. (READ만 가능)

<servlet>
   <servlet-name>main</servlet-name>
   <servlet-class>com.MainServlet</servlet-class>
   <init-param>
      <param-name>title</param-name>
      <param-value>홈페이지</param-value>
   </init-param>
</servlet>
ServletConfig config = this.getServletConfig();
String title = config.getInitParameter("title");
>>> session-config : 30분설정
<session-config>
   <session-timeout>30</session-timeout>
</session-config>
>>> Servlet/JSP 정의 및 매핑
<servlet>
   <servlet-name>{서블릿이름}</servlet-name>
   <servlet-class>{서블릿이름에 해당하는 클래스}</servlet-class>
</servlet>
<servlet-mapping>
   <servlet-name>{서블릿이름}</servlet-name>
   <url-pattern>{클라이언트가 요청할 url패턴}</url-pattern>
</servlet-mapping>
url-pattern의 설정법
> 이름까지 정확히 일치
   /[경로]/이름
> 디렉토리까지 일치
   /[경로]/*
> 확장자만 일치
   *.확장자
>>> mime type 매핑

특정파일을 다운로드 시켰을때 다운로드창이 아닌 파일이 깨져보일때 정상적인 다운로드를 위해 설정해야 한다.

<mime-mapping>
   <extension>xls</extension>
   <mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>
* mime type
엑셀 97~2003 통합문서 (*.xls)
> application/vnd.ms-excel
엑셀 통합문서 (2007 이상 *.xlsx)
> application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
ZIP 파일 (*.zip)
> application/zip
TAR 파일 (*.tar)
> application/x-bzip
워드 97~2003 문서 (*.doc)
> application/msword
워드 문서 (2007 이상 *.docx)
> application/vnd.openxmlformats-officedocument.wordprocessingml.document
PDF 파일 (*.pdf)
> application/pdf
한글 (*.hwp)
> application/x-hwp
>>> Welcome File list

도메인으로만 접근하였을때 최초로 보여질 페이지를 지정한다.

<welcome-file-list>
   <welcome-file>index.html</welcome-file>
   <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
>>> Error Pages 처리

error 발생시 안내 페이지를 지정한다.

<error-page>
   <error-code>500</error-code>
   <location>/500.jsp</location>
</error-page>
>>> 리스너/필터 설정

– Listener : 어떠한 이벤트가 발생하면 호출되어 처리하는 객체로 인터페이스만 제공되므로 클래스는 직접 구현해야한다.

<listener>
   <listener-class>{구현된 클래스 경로}</listener-class>
</listener>

– Filter : HTTP요청과 응답을 변경할 수 있는 재사용가능한 코드로 클라이언트와 서블릿 사이에 위치하여 request & response값을 알맞게 변경 할 수있게 한다.

<filter>
   <filter-name>{필터명}</filter-name>
   <filter-class>{클래스 경로}</filter-class>
</filter>
<filter-mapping>
   <filter-name>{필터명}</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>