1. HTTPServlet
- Servlet을 만들기 위해 반드시 상속해야 할 필수 Class임
- 주요 Method
- void init()
- Servlet의 Object가 add될때 call되는 method임
- void destroy()
- Servlet의 Object가 Memory에서 사라질 때 Call되는 Method임
- void service(request, response)
- Servlet의 Request가 있을때 Call되는 Method임
- void doGet(request, response)
- Html에서 form의 method가 get일때 call되는 method임
- void doPost(request, response)
- Html에서 form의 method가 post일때 call되는 method임
2. HTTPServletRequest
- Client가 Data를 입력하거나 Client의 정보에 대한 Request value를 가지고 있는 Class임
- 주요 method
- String getParameter(name)
- name에 할당된 값을 return하며 지정된 Parameter value가 없으면 null value를 return 해줌
- String[] getParameterValues(name)
- name의 모든 value를 String Array로 Return해줌
- Enumeration getParameterNames()
- Request에 사용된 모든 Parameter name을 java.util.Enumeration Type으로 Return 함
- void setCharacterEncoding(env)
- Post방식으로 Request된 String의 character encoding을 설정함
3. HTTPServletResponse
- Client가 Request한 info를 처리하고 다시 Response하기 위한 info를 담고 있는 Class임
- 주요 method
- void setHeader(name, value)
- Response에 포함될 Header를 설정함
- void setContentType(type)
- 출력되는 page의 contentType을 설정함
- String getCharacterEncoding()
- Response page의 String encoding Type을 Return 해줌
- void sendRedirect()
4. HTTPSession
- Client가 Session을 info에 저장하고 Session 기능을 유지하기 위해서 제공되는 Class임
- 주요 Method
- String getId()
- 해당 Session의 Session ID를 반환함
- long getCreationTime()
- long getLastAccessedTime()
- Client Request를 마지막으로 시도된 시간을 반환함
- void setMaxInactiveInterval(time)
- Session을 유지할 시간을 초단위로 설정함
- int getMaxinactiveInterval()
- setMaxInactiveInterval(time)로 지정된 값을 반환함(default : 30m)
- boolean isNew()
- Client Session ID를 할당하지 않은 경우 true value를 반환함
- void invalidate()
5. Servlet Life Cycle
- 순서도 : Client Servlet Request → init(최초 한번 Call) → Service, doGet, doPost(반복적 call) → destroy(Last 한번 Call)
- init() - Servlet이 처음으로 Request되어 Object가 생성될 때 Call되는 Method임
- service() - Clinet가 Request 있을 때마다 call되는 Method임
- destroy() - Servlet service의 종료 및 재시작 and servlet code가 수정이 될 때 call되는 method임
- doGet() - Client Request할 때 Form의 method가 GET방식일 때 call되는 method임
- doPost() - Client Request할 때 Form의 method가 POST방식일 때 call되는 method임
6. Servlet Interface