Advanced Java Programming
1. Architecture of JSP Technology
JSP (Java Server Pages) follows the Model–View–Controller (MVC)
architecture and is built on top of Servlet technology. Its architecture
includes the following components:
(a) JSP Pages
Written using HTML + JSP tags + Java.
Contain the presentation logic.
Compiled into Servlets by the JSP engine.
(b) JSP Engine / Container
Part of the web server (e.g., Tomcat, Jetty).
Responsible for:
o Translating JSP into Servlet code
o Compiling the servlet
o Managing execution, memory, sessions
(c) Web Server
Receives the client request.
Passes it to the JSP container.
Sends the generated HTML output back to the client.
(d) Java Servlet API
JSP ultimately becomes a Servlet.
Uses Servlet classes such as:
o HttpServletRequest
o HttpServletResponse
o HttpSession
o ServletContext
(e) Backend Services
Database (MySQL, Oracle)
JavaBeans (business logic)
EJB / external APIs
Architecture Flow Diagram (Text Description)
1. Client (Browser) → sends HTTP request
2. Web Server → forwards to JSP container
3. JSP Container
o Checks if JSP is already compiled
o If not, translates JSP → Servlet → compiles it
4. Servlet Engine executes the servlet
5. Servlet produces HTML output
6. Web server sends response back to Client
2. JSP Page Life Cycle (JSP Life Cycle)
A JSP page goes through five main phases:
1. Translation Phase
JSP file (.jsp) is translated into a Java Servlet file (.java).
Performed by the JSP engine automatically.
2. Compilation Phase
The generated Java servlet file is compiled into bytecode (.class
file).
3. Class Loading and Instantiation
The compiled servlet class is loaded into memory.
JSP container creates an instance of the servlet.
4. Initialization — jspInit()
Called only once per JSP lifecycle (like init() in servlets).
Used to initialize resources (DB connections, files).
5. Request Processing — _jspService()
Called for every client request.
Handles request and response objects.
Generates dynamic content (HTML output).
6. Destruction — jspDestroy()
Called when the JSP is removed from container or server shutdown.
Used to close DB connections or clean up resources.
JSP Life Cycle in Order
1. Translation → JSP → Servlet
2. Compilation → Servlet class
3. Class Loading
4. Object Instantiation
5. Initialization (jspInit())
6. Request Processing (_jspService())
7. Destruction (jspDestroy())
JSP directives
JSP directives are JSP components that are used to give the instructions to
the JSP compiler.
JSP directives will simplify writing JSP files.
These tags are used to give directions to the JSP page compiler.
In web applications, JSP Directives can be used to define present JSP page
characteristics, to include the target resource content into the present JSP
page, and to make available user-defined tag library into this JSP page.