톰캣 DataSource 설정 및 사용

 - JDBC 드라이버를 \WEB-INF\lib 폴더에 설치

 - ConnectionPool 기능 관련 jar 파일 \WEB-INF\lib 폴더에 설치

 - %CATALINA_HOME%\context.xml에 Connection 객체 생성시 연결할 데이터베이스 정보를 jndi로 설정

 - DAO 클래스에서 DB 연동시 미리 설정한 JNDI라는 이름으로 DB와 연결하여 작업

 

포워드: 서블릿에서 다른 서블릿이나 서블릿에서 JSP로 request를 전달함

 - redirect: HttpServletResponse객체의 sendRedirect("포워드할 서블릿 또는 JSP")

 - refresh: HttpServletResponse객체의 addHeader("Refresh", "경과시간(초);url=요청할 서블릿 또는 jsp")

 - location: 자바스크립트 location 객체의 href 속성을 이용

 - dispatch: RequestDispatcher 클래스의 request.getRequestDispatcher("포워들할 서블릿 또는 jsp").forward(request, response)

 

redirect, refresh, location은 브라우저를 거쳐서 서블릿이나 JSP에 요청하는 방법

dispatch는 클라이언트를 거치지 않고 바로 서블릿으로 요청하는 방법

 

Binding

 - 웹프로그램 실행시 서블릿 관련 객체에 데이터를 저장하는 방법으로 HttpServletRequest나 HttpSession, ServletContext 에 사용 됨

 - setAttribute, getAttribute, removeAttribute

 

ServletContext와 ServletConfig

https://stackoverflow.com/questions/4223564/servletconfig-vs-servletcontext

 

ServletConfig vs ServletContext

What is the difference between ServletConfig and ServletContext interface?

stackoverflow.com

서블릿 초기화 및 load-on-startup 사용

 - web.xml

 - @WebServlet

 

서블릿 응답, 요청 API

 - 요청 관련 API: javax.servlet.http.HttpServletRequest

 - 응답 관련 API: javax.servlet.http.HttpServletResponse

 

<form> 태그로 전송된 데이터를 받아오는 HttpServletRequest 메소드

메소드 기능
String getParameter(String name)  
String[] getParameterValues(String name)  
Enumeration getParameterNames()  

 

서블릿의 응답 처리 방법

 - 브라우저와 서블릿의 통신은 자바 I/O 스트림 이용

 - MIME-TYPE

   > 서버에서 웹 브라우저에게 어떤 종류의 데이터를 전송하는지 알려줘야 빠르게 처리 가능

   > 따라서 웹 컨테이너에서 미리 제공하는 여러 가지 전송 데이터 종류 중 하나를 지정하여(setContentType()) 웹 브라우저로 전송

   > 컨테이너에서 미리 설정해 놓은 데이터 종류들을 MIME-TYPE이라고 한다.

Servlet API

https://www.codejava.net/java-ee/servlet/servlet-api-overview

 

Servlet API Overview (UML class diagram)

 

www.codejava.net

servlet-api.jar

 

서블릿 매핑

 - web.xml <servlet>, <servlet-mapping> 태그

 - 애너테이션을 이용한 매핑 @WebServlet

웹 애플리케이션 디렉토리 구조

http://www.javawebtutor.com/articles/servlets/structure_of_java_web_application.php

 

Directory Structure Of Java Web Application | Java Web Tutor

 

www.javawebtutor.com

 

웹 컨테이너에 웹 애플리케이션 등록

1) %CATALINA_HOME%\webApps 디렉토리에 애플리케이션 저장

2) server.xml에 웹 애플리케이션 등록

 

Context

 - server.xml에 등록하는 웹 애플리케이션

 - 웹 컨테이너(톰캣)가 server.xml에 등록되어있는 컨텍스트 위치로 이동하여 애플리케이션을 실행

 - 웹 애플리케이션당 하나의 컨텍스트 등록

 - 웹 애플리케이션과 이름이 같을 수도 다를 수도 있음

 - %CATALINA_HOME%\conf\server.xml

 

배치(deploy)

+ Recent posts