Professional Documents
Culture Documents
(JSP)
PRESENTED BY:
Manisha Keim
Introduction
JSP (Java Server Pages) is server side technology to create
dynamic java web application.
Allows Java programming code to be embedded in the HTML
pages.
JSP contains an extension of .jsp
After execution of a JSP page a plain HTML is produced and
displayed in the client's Web browser.
JSP can be thought as an extension to servlet technology
because it provides features to easily create user views.
JSP Architecture
URL
JSP page
request
HTTP request
JSP container
compiles to properties, JavaBean
a servlet call methods Library
response
HTTP response
HTTP page
DB
The following steps explain how the web server creates the web page using JSP:
As with a normal page, your browser sends an HTTP request to the web server.
The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine. This
is done by using the URL or JSP page which ends with .jsp instead of .html.
The JSP engine loads the JSP page from disk and converts it into a servlet content. This conversion is very
simple in which all template text is converted to println( ) statements and all JSP elements are converted to
Java code that implements the corresponding dynamic behavior of the page.
The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet
engine.
A part of the web server called the servlet engine loads the Servlet class and executes it. During execution,
the servlet produces an output in HTML format, which the servlet engine passes to the web server inside
an HTTP response.
The web server forwards the HTTP response to your browser in terms of static HTML content.
Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if
it were a static page.
Loading
Compilation Instantiation
JSP
Translation
LIFECYCLE Initialization
Destroy Request
JSP Life Cycle
Web Server
Step: 1
hello.jsp hello_jsp.java
Web Container
Step: 7
Step: 6 jspDestroy() Step: 2
jspService()
Once a JSP page is translated to a servlet, the container invokes the following life
cycle methods on the servlet :
• jspInit() : This method is invoked at the time when the servlet is initialized.
• jspService() : This method is invoked when request for the JSP page is received.
• jspDestroy() : This method is invoked before the servlet is removes from the
service.
What happens to a JSP page when it is
translated into Servlet
JSP Elements
• EXPRESSION enclosed in <%= and %> markers
A expression is used to insert the result of a Java expression directly into the
output.
The time is : <%= new java.util.Date() %>
To Display:
"Good Morning", if it is between 3:00am and 12:00pm
"Good Afternoon", if it is between 12:00pm and 6:00pm
"Good Evening", if it is after 6:00 pm
References
http://www.studytonight.com/jsp/lifecycle-of-jsp.php
https://www.ntu.edu.sg/home/ehchua/programming/java/JSPB
yExample.html
http://met.guc.edu.eg/OnlineTutorials/JSP%20-
%20Servlets/A%20simple%20JSP%20example.aspx
Head First JavaScript Programming: A Brain-Friendly Guide
https://www.tutorialspoint.com/java/java_environment_setup.h
tm
THANK YOU ☺
S