Java Server Pages is a server side technology which helps to create a webpage dynamically using java as the programming language. JSPs are built on top of SUN Microsystems' servlet technology. JSP files have the extension with .jsp. Inside a jsp page contains the html embedded with some jsp tags. The jsp pages only processed by the web servers which contains the jsp engine.
Flow of JSP Architecture
Here follows the flow of JSP Architecture
- The user sends a jsp page request through his web browser.
- Browser sends the request to the Web Server (tomcat or jboss)
- The webserver accepts the .jsp file and passes the jsp file to JSP Engine
- If it is the first time the that jsp call, then jsp become parsed else servlet instantiated. Then it generate a servlet from the jsp file.
- Then the generated servlet output send back to the browser via internet
- The browser displays the html result to user
The following picture shows the pictorial representation of jsp flow
JSP Lifecycle Phases
Here follows the each phases contains in a JSP lifecycle
Transilation - The JSP container parses the JSP pages. It then translate the JSP pages to generate corresponding servlet source code. If JSP file name is hello.jsp, usually it is named as hello_jsp.java by the container.
Compilation - If the translation is successful, the generated java file is then compiled by the container.
Class Loading- Once JSP is compiled as servlet class, its lifecycle is similar to servlet. The compiled class is then loaded into the memory.
Instance Creation - Once JSP class is loaded into memory, its object is instantiated by the container.
Call jspInit() or Initialization - During this phase the JSP class is initialized transformed from a normal class to servlet. Once initialization is over, ServletConfig and ServletContext objects become accessible to JSP class. Method jspInit() is called only once in JSP lifecycle. It initializes config params.
Call _jspService or Request Processing - This method is called for each client request.
Call jspDestroy or Destroy - This is the last phase and this method is called when the container decides to unload JSP from memory.
JSP Lifecycle Implementation
Now we can take a look on jsp package. the javax.servlet.jsp package defines two interfaces which are JSPPage and HttpJspPage. These interface defines three methods for compiled jsp page which are
jspInit(); jspDistroy(); _jspService(HttpServletRequest request,HttpServletResponse response)
Here jspInit() and jspDistory() methods can override by the user but the _jspService(HttpServletRequest request,HttpServletResponse response) is generated by the JSP Engine.
No comments:
Post a Comment