2008. 9. 8. 14:54

JSP/Servlet 기본

@servlet-->was에서 실행되는 자바클래스를 만드는 규칙.
was(web application server)


-JavaEE 기술명세에 따라 작성된 서버
--톰켓(web:servlet/Jsp)
--weblogic(web+ 분산기능(EJB)):Bea's
--websphere:IBM's
--JEUS:Tmax's
--sun Java System AS9:sun's

 

@ Servlet 기술
- JavaEE 구현서버에서 실행되는 자바 클래스 만들기.

 interface (규칙): caller 와 callee사이의 규칙
 -callee(규칙을 준수하는 자바 클래스)가 갖춰야할 기능을 선언하고 있다.
 -caller가 이 기능을 사용(call)할 수있다.


caller (WAS) - servlet container : 생성과 사용 소멸 관리.
 servlet의 생성과 사용 소멸관리.(life-cycle)
Servlet Interface?
 -Caller 인 "Servlet Container"와 callee인 "Web Application " 사이의 호출 규칙


Servlet Container?
 Servlet Web Application의 life-cycle을 관리하는 서버
Servlet Application ?
 -Servlet Container에 의해 실행가능하도록 servlet규칙에따라 작성된 웹 애플리케이션


Servlet 규칙의 기능 명세?
-init() : Servlet Container가 서블릿을 생성 시킨후 초기화를 수행하기 위해 호츨..
-service() : Servlet Container가 클라이언트의 요청에 대해 작업을 수행하기 위해 호출.
-destory() : Servlet Container가 서블릿을 메모리에서 제거하기 전에 마무리작업을 위해 호출.
-getServletConfig()
-getServletInfo()

 

@ callback method(function)? 
-만든 메소드를 Application 이 호출하지 않고, Container 나 Server, OS 에서 호출하는 경우.


@ Web Servlet App. 서버에 배치하는 방법(deploy)..?
-JavaEE 구현(기술명세에 따라 만든)서버에 웹 에플리케이션을 배치.
 즉 "톰켓서버에 배치했다" 등의 표현.

@Web Application 배치 방법?
 -디렉토리 또는 묶음파일(*.war)로 서버의 특정 디렉토리에 올린다.


 - 디렉토리 구조.
StudyWeb.war
 /WEB_INF/web.xml       <--- 배치 설명 파일(Deployment Descriptor File:DD File)
  /classes <--- 컴파일된 클래스 파일
  /lib  <--- 컴파일 된 클래스 파일들을 .jar 파일들.
 /...   <--- 기타


@ Servlet 생성후 배치설명 파일에 등록?
-web.xml 파일에 Servlet에 대한 정보를 등록
-서블릿 정의 방법:
 <servlet>
         <servlet-name>HelloWorld</servlet-name>                  <-- servlet명
         <servlet-class>study.servlets.Hello</servlet-class>      <-- servlet 클래스 명
    </servlet>
-서블릿 서비스 이름(클라이언트에서 사용할 이름) 등록 방법:
 <servlet-mapping>
         <servlet-name>HelloWorld</servlet-name>           <-- 위에서 정의한 서블릿명
         <url-pattern>/Hi</url-pattern>                           <-- client에서 사용할 별명(url)
  </servlet-mapping>
@ Fully Qualified Name?(QName)
-패키지명을 포함한 클래스명


@ Context name?
- 웹 application 이름.
- 즉 클라이언트에서 접근할때 사용할 웹 application 이름


@public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        //web browser에 출력할 내용을 작성...개발자가..
    }
- 서블릿은 오직한번만 호출된다. 서비스메소드 안에 수행할 작업을 작성

 

@ Servlet 작성절차?
1) Servlet 인터페이스 구현 클래스 작성
2) web.xml 파일에 Servlet 클래스 정보 등록
3) 서버에 deploy (setup, install의 의미)


@ Servlet? Servlet App.
- 클라이언트에게 특정 서비스를 제공하기 위해 만들어진 Server-Side Application.
- javaEE 기술명세에 따라서 만든 서버에 의해 실행되는 프로그램.
- 서비스당 하나의 서블릿 하나를 만들어야한다.

 

@ GenericServlet??
--실제 service() 메소드에 구현에 관심..
--service() 메소드를 제외한 나머지 메소드를 미리 구현했음.
--개발자를 위한 도우미 클래스.
--javax.servlet.Servlet 인터페이스를 구현했음. 오직 하나의 메소드만을 구현하지 않았음..(service)

--추상클래스.

 

@ServletRequest??
- caller ? Servlet Application.
- callee ? Servlet Container
-Client 의 요청정보를 다루는 규칙(기능들)

 

@ServletResponse??
- caller ? Servlet Application.
- callee ? Servlet Container
-Client 로의 응답과 관련된 규칙

 

@service() 메소드에 넘어오는 파라미터(값)?
-ServletContainer가 값을 넘긴다.
-파라미터는?? ServletRequest와 ServletResponse 규칙에 따라 작성된 객체


@ Servlet의 출력에서 한글이 깨진다면 ??
- Servlet에서 출력할때 기본적으로 Unicode --> ISO-8859-1 로 변환 시키기 때문.
- ISO-8859-1(ISO-Latin-1): 영어및 유럽문자에 대한 코드(신호)정의. 한글에 대한 정의는 없다.
- 해결 : 출력스트림 객체를 얻기 전에 어떤 Character Set으로 변환할 지를 설정해야한다.
- res.setContextType("text/html;charset=UTF_8");

 

@ HTTP protocol??(www.w3.org)
-Web Server 와 Web Browser사이의 통신(요청/응답) 프로토콜.


@ HTTPRequest?
 - Web Browser에서 Web Server로 요청하는 형식

request-line
header-line*
CRLF
(message body)

예)
Accept: */*
Accept-Language: ko
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)

@ HTTPResponse?
- 웹서버가 웹브라우저에게 응답하는 형식

Status-line
header-line*
CRLF
(message body)

예)
HTTP/1.1 200 OK
X-Powered-By: Servlet/2.5
Content-Type: text/html;charset=UTF-8
Content-Length: 106
Date: Mon, 19 Mar 2007 13:42:28 GMT
Server: Sun Java System Application Server Platform Edition 9.0_01
Connection: close

<html>
<head><title>?븞?뀞?븯?꽭?슂</title></head>
<body>
<h1>?씤?궗</h1>
Hello!!!
</body>
</html>


@HEAD 요청방식??
- 서버에 요청자원의 HEAD정보만 요구함.
*프록시 서버를 개발할 경우 head를 사용한다.( 날짜를 가져오고 비교함 )

'My work space > JSP/Servlet' 카테고리의 다른 글

request.getAttribute  (0) 2008.09.08
jsp/Servlet 기본2  (0) 2008.09.08
게시판만들기-검색하기(펌)  (0) 2008.09.08
게시판만들기-페이지나누기(펌)ASP  (0) 2008.09.08
게시판 만들기 - 수정, 삭제하기(펌)  (0) 2008.09.08