Skip to main content

JSP Life Cycle

a.)InstantiationEvent(when container creates JES class object)

Life cycle methods
These life cycle methods will be called through servlet life cycle method(init(ServletConfig))
1.)jspInit()->for programmers initailization logic
2.)_jspInit()->for container initialization logic

b.)Request Processing Event
Life cycle methods
These method will be called through servlet life cycle method 1st service(req,res)
1.)_jspService(-,-)

c.)Destruction Event(When container is about to destroy JES class object)
Life cycle methods
These methods will be called through destroy() life cycle method of servlet component
1.)jspDestroy()-->for programmer
2.)_jspDestroy()-->for container

JSP life cycle methods are called through servlet life cycle methods with support of JES class super class(HttpJspBase in tomcat server)


Two phases of JSP

a.)Phase-1(Translation Phase)
Here jsp pages will be translated into an equivalent servlet class source
first.jsp--pageCompiler-->first_jsp(JES source code)

b.)Phase-2(Request Processing/Execution Phase)
1.)Here jes class will be compiled, jes class will be loaded, instantiated and initialized

2.)calls _jspService(-,-) to process the request and to generate the response
first_jsp.java---->first_jsp.class--->_jspService(-,-) and response goes to browser...



3.)The request given to jsp directly particulates in request processing/ execution phase, if the jsp source code is not modified compares to previous request and JES class compiled code is already available otherwise the request given to jsp participates in request processing phase and execution phase

4.)If JES class source is deleted, then the request given to jsp doesn't participates in request translation phase

Note: The jsp container internally preserves the jsp source code for every request until next request comes to that jsp and compares both source code(current request & previous request) by using special tools like WDIFF, ARAXIS, WINMERGE and etc... to check whether modifications taken place or not

5.)When <load-on-startup> is enabled on jsp component the jsp container performs following operations either during server startup or during the deployment of web application so the first request given to jsp directly participates in request processing due to these we can minimize response time of first request and we can equalize with other than first request

6.)The operations are
Jsp loading-->jsp parsing-->jsp translation(page compilation)-->JES compilation-->JES class loading-->JES class instantiation-->JES class initialization
Example:
  1. <servlet>
  2.    <servlet-name>one</servlet-name>
  3.    <jsp-file>/WEB-INF/pages/first.jsp</jsp-file>
  4.    <load-on-startup>1</load-on-startup>
  5. </servlet>
  6.  <servlet-mapping>
  7.       .....
  8.  </servlet-mapping>
7.)The modifications done in JES class will not be reflected in the response that goes to browser irrespective of the recompilation of JES class and reloading of web application

Note:
There is no needing of configuring generated JES class in web.xml, because that class is generated by jsp container itself. So there is no need of configuring that class

Comments

Popular posts from this blog

JSP Comments

Comments in JSP:- -->Compiler /Interpreter doesn't take commented code for compilation /Interpretation, so the commented code doesn't participate in execution JSP supports 3 types of comments:- a.)HTML comments /Template text comments/ Output comments Syn :- <!---text---> -->Recognized by html interpreter of browser b.)JSP comments /Hidden comments Syn :- <%--text--%> -->JSP page compiler recognize these comments c.)Java comments /Scripting comments Syn :- //-->For single line /*-- -----*/-->For multiple line -->Java compiler(java) recognize these comments -->In Eclipse IDE JES class for first.jsp comes in our(workspace)folder/.metadata/.plugins/.org eclipse Comments (1)JSP comment<%--%> (2)Java comment(// or /*--*/) (3)HTML comments(<!---> JES Source Code (1)No (2)Yes (3)Yes In JES compiled code (1)No (2)No (3)Yes In the code going to browser (1)No (2)No (3)Yes Output (1)No (2)No (3)No -->Jsp comments are not visible in any phase

Scripting Tags

JSP Tags/ Elements (1)Scriptlet     Standard syn:-         <%.........%>     xml syn:-        <jsp:scriptlet>...</jsp:scriptlet> Note: All scripting tags allows us to place script code(java code) 1.)The code placed in scriptlet go to _jspService(-,-) of JES class 2.)In a jsp page we can have zero or more scriptlets 3.)We place request processing logics in scriptlets 4.)Variables declared in scriptlets becomes the local variables in _jspService(-,-) of JES class in first.jsp In first.jsp: <% int a=10;  out.println("square:"+(a*a));%> In first_jsp.java(JES): public class first_jsp extends..{     public void _jspService(-,-){        int t=30;        out.println(“Square:”+(t*t));     }  } The code placed in scriptlet can use implicit objects of jsp because implicit objects and the code placed scriptlet goes to _jspService(-,-) method of JES class first.jsp Browser s/w name: <%out.println(request.getHeader("user-agent");%> first_jsp.java pu

Project Architecture's

1.) Functional flow/ Architecture a.) Only for 6+/7+years b.) Explain the flow of process/business 2.) Technical Flow/Architecture a.) Upto 5+ years b.) Explain technologies /components that are involved in the project Servlet & JSP Project Architecture:- 1.)What is need of Business Deligate to convert VO class object to DTO class object ? a.) If Business Deligate is not there servlet component directly prepares DTO class object by receiving and translating form data and passes to service class, if service class excepts certain input in other format like numeric employee number as string employee number then we need to modify servlet component code i.e For the changes that happened in business tier service component we have to modify servlet component of presentation tier b.) If Business Deligate is taken then it gets original form data as VO class object having string inputs and converts VO class object to DTO class object to pass to service class c.) If service class excepts