SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
Lecture 5
Java Server Page (JSP) in J2EE
L5.1 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
JSP Basic Concepts
• JSP is a server-side programming technology, like
Microsoft ASP. It is an integral part of Jakarta EE for
enterprise applications.
• JSP can create a dynamic and platform-independent
web application.
• JSP can access to all the powerful enterprise Java API,
like JDBC, EJB, …, etc.
• JSP is made of HTML and JSP elements.
L5.2 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
JSP Architecture
L5.3 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
JSP Life Cycle
1. Translation – translate JSP into servlet source (java)
2. Compilation – compile servlet source into class (if
never compiled or modified since last compilation)
3. Initialization – load servlet and perform init() method
once (e.g. initialize db connection)
4. Execution – handle all interactions with request
(HttpServletRequest) and response
(HttpServletResponse) services
5. Cleanup – destroy servlets from a container
L5.4 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
JSP Life Cycle
L5.5 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
• JSP elements: There are three types of JSP elements
• Scripting Element – contains Java statements, variable/
method declarations, expressions or comments.
• Directive Element – provide directions and instructions to
the container how to handle certain aspects of JSP.
• Action Element – control the behaviour of servlet engine.
L5.6 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
JSP Element
L5.7 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
• Implicit Objects: Tomcat implicitly creates within JSP
pages.
• Application Objects - It is an instance of
ServletContext object. It provides access to the
resources shared within the web application.
• Session Object: It is an instance of
jakarta.servlet.http.HttpSession object. It is used to
track client session between client requests.
L5.8 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
• Implicit Objects: Tomcat implicitly creates within JSP
pages.
• PageContext Object: It is an instance of
jakarta.servlet.jsp.PageContext object. It is used to
represent the entire JSP page.
• Request Object: It is an instance of
jakarta.servlet.http.HttpServletRequest object and
represents a request from the client.
L5.9 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
• Implicit Objects: Tomcat implicitly creates within JSP
pages.
• Out Object: It is familiar to System.out object in
Java.
• Response Object: It is an instance of
jakarta.servlet.http.HttpServletResponse object and
represents the response to the client from server.
L5.10 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
• Form Processing: Two methods to pass data to web
server:
• By GET method: parameters appended to the page
request in URL or form.
• By POST method: The parameters will be hidden in
URL.
L5.11 SEHS4701
SEHS4701 ADVANCED INFORMATION SYSTEMS
DEVELOPMENT
The End
L5.12 SEHS4701