servlet - spring

 

SERVLET life cycle

  1. init() 초기화

The servlet is initialized by calling the init() method.

서블릿은 클라이언트가 요청해준후 바로 호출이 되는 것이 아니라 객체를 생성하고 초기화 작업을 거친 후 , 요청을 처리한다.

  1. servlet

service() → doxxx() ,The servlet calls service() method to process a client's requesst.

servlet 에서 service() 를 호출 ⇒ doxxx() 들에서 어떤것을 선택한다 ( get, post , )

  1. destory()

The servlet is terminated by calling the destroy() method.

The destroy() method is called only once at the end of the life cyle of a servlet. This method gives your servlet a chance to close database , halt background threads , write cookie lists or hit counts to disk, and perform other such cleanup activities

After the destroy() method is called, the servlet object is marked for garbage collection.

  1. Finally, servlet is garbage collectd by the garbage collector of the JVM

be cited from https://www.tutorialspoint.com/servlets/servlets-life-cycle.htm

Type of Http request type

The servlet container(i.e web server) calls the service() method to handle request coming from the client(browsers) and to write the formatted response back to the client

Each time the server receives a request for servlet, the server spawns a new thread and calls service . The service() method checks the HTTP request type(Get, Post, Put, Delete etc. )

you override either doGet() or doPost() depending on what type of request you receive from the client

  1. The doGet() Method

A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method

  1. The doPost() Method

A POST request results from an HTML form that specifically lists POST as the Method and it should be handled by doPost() Method

servlet life-cycle scenario

first the HTTP requests coming to the server are delegated to the servlet container.

The servlet container loads the servlet before invoking the service() method

Then the servlet container handles multiple requests by spawning multiple threads, each executing the service() method of a single instance of the servlet

댓글