JAVA Servlet 프로젝트 구조

KSOJIN·2023년 7월 13일
0

taxcare

목록 보기
8/10
post-thumbnail

▶ WebContent : 사용자가 jsp파일에 직접 접근할 수 있음

▶ WEB-INF : 직접 접근이 어렵고 Controller를 통해서만 이동가능

▶ web.xml : 브라우저가 Servlet에 접근하기 위해 WAS(Tomcat)에 필요한 정보를 알려주는 역할

  1. 배포할 Servlet이 무엇인지
<servlet>
  	mapping servlet-name과 같아야 함
  	<servlet-name>welcome</servlet-name> 
  
  	작성한 클래스 이름 (패키지.클래스)
  	<servlet-class>servlet.welcomServlet</servlet-class>
</servlet>
  1. 해당 Servlet이 어떤 URL에 매핑되는지
<servlet-mapping>
  	<servlet-name>welcome</servlet-name> 
  
  	클라이언트의 요청 URL에서 앱(프로젝트) 이름 뒤에 오는 부분으로 '/'로 시작
  	<url-pattern>/welcome</url-pattern>
</servlet-mapping>

※ 클라이언트가 요청하는 URL 정보
서버의 IP 주소 : Port 번호 / App이름 / 요청하는 HTML
ex) localhost:8080/TestApp/login.html

▶ context.xml : DB connection 연결하기 위해 WebContext/META-INF에 생성

출처 https://hotdogya.tistory.com/98

1. context.xml에 리소드 등록

<Context>
	<Resource
              name="jdbc/myoracle"
              auth="Container"
              type="javax.sql.DataSource"
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@localhost:1521:xe"
              username="username"
              password="password"
              maxActive="20"
              maxIdle="10"
              maxWait="-1"
              />
</Context>
  • name : JNDI로 호출될 이름
  • auth : DBCP를 관리할 관리자 (Container or Application)
  • type : return type (DataSource는 Connection 객체를 반환할 수 있음)
  • driverClassName : JDBC를 이용하기 위한 드라이버 클래스
  • url : DB 접속 URL
  • maxActive : 최대 접속 허용 개수
  • maxIdle : DB Pool에 여분으로 남겨질 최대 Connection 개수
  • maxWait : DB 연결이 반환되는 Timeout의 최대 시간 (-1은 무한 대기)

2.web.xml에 JDNI로 정의할 이름을 등록

<resource-ref>
  <description>SQL Resource</description>
  <res-ref-name>jdbc/myoracle</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>
  • description : 리소스 설명
  • res-ref-name : context.xml에 등록한 리소스 이름
  • res-type : 리턴 타입
  • res-auth : 관리 계층

0개의 댓글