servlet life cycle :
1. Class loading
2. Instantiation
3. Initialization by invoking init()
4. service by invoking service()
5. Destruction by invoking destroy()
servlet container/web container/application server :
servlet container : It is the component of web server which is responsible to manage servlet
life cycle.
When the request is sent to any specific servlet then the servlet container will create request
and response objects internally.
JSP
JSP stands for java server page. JSP is a technology which has been developed on top of
servlet technology itself. Servlets can be used if the focus is more on java logic and JSP's can
be used if the focus is more on HTML logic.
All the JSP files will be translated into servlets by jsp translator.
JSP Tags
1. Declaration tag => <%! %> => This tag is used to declare the variables or methods of a
java.
2. Scriptlet tag => <% %> => This tag is used to write java logic for dynamic response.
3. Expression tag => <%= %> => This tag is used to print results on web browser.
4. Directive tag => <%@ %> => This tag is used to import external resources in a JSP file.
All the JSP files are capable of serving only HTTP requests because all the JSP files will be
translated into HttpServlet.
JSP life cycle :
JSP lie cycle is very much similar to servlet life cycle.
Different phases of JSP life cycle
1. JSP file will be translated to the servlet by the component called as JSP translator.
2. The translated servlet class will be loaded.
3. An instance will be created for the servlet class.
4. The servlet instance will be initialized by invoking jspInit() method.
5. The service will be provided for the request by invoking _jspService() method.
6. Once the server stops, the jsp will get destroyed by invoking jspDestroy().
Servlet container itself will manage the JSP life cycle.
Servlets are faster than JSP's in giving responses.