Thursday, June 9, 2022

Lifecycle phases of JSP

 Lifecycle phases of JSP

Lifecycle phases of JSP
java 


There are 6 different lifecycle phases present for JSP namely:-

  1. Translation Phase
  2. Compilation Phase
  3. Instantiation / Object Creation Phase
  4. Initialization Phase
  5. Service Phase
  6. Destruction Phase


Lifecycle methods of JSP

There are 3 different lifecycle methods present for JSP namely:-

  1. jspInit() ====> @Override
  2. jspService(HttpServletRequest req, HttpServletResponse resp)
  3. jspDestroy() ===> @Override



Note:- JSP is used to give Presentation Logic.


Q) Why is JSP used to give Presentation Logic instead of Html?

  Ans:- JSP is used to give Presentation Logic instead of HTML because of code simplification.



Contents of JSP:

1. Html

2. PageDirective:- default content of JSP.

3. Scriptlet:-It is the area which is used to write the Java Code File.

                 In case of JSP, Sciptlet is represented as <%     %>

                 Ex:-

                       <% out.println(2*5) %>


4. Expression:- It is used to represent or print the Java Codes i.e Output.

  In the case of JSP, Expression is represented as <%= %>


5. Declarative:- Data which are declared on an XML File.

        web.xml   ---> pom.xml[Maven] --- internet


Note:-

1. Most of the contents of JSP fit into _jspService().

2. The Naming convention followed by Apache Tomcat Server to store all the TranslatedServlet into the work folder of Apache Tomcat Server is [Filename_jsp.java].

  Eg:-

        If the Filename is Test.JSP, then TranslatedServlet name while sharing into the work folder is Test_jsp.java.


0 comments:

If you have any doubts,please let me know