0% found this document useful (0 votes)
5 views

Lecture 43

Uploaded by

abhiarumishra063
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lecture 43

Uploaded by

abhiarumishra063
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Web Technology

(KCS-602)
Unit 5
Java Server Pages (JSP): Introduction

Prepared By
Sachin Kumar Sonker
Assistant Professor,UCER Naini,Allahabad
Index
• About JSP
• Advantages of JSP
• Architecture of JSP
JSP
• Java Server Pages (JSP) is a server-side programming
technology that enables the creation of dynamic,
platform-independent method for building Web-
based applications.
• JSP have access to the entire family of Java APIs,
including the JDBC API to access enterprise
databases.
• JSP tags can be used for a variety of purposes, such
as retrieving information from a database or
registering user preferences, accessing JavaBeans
components, passing control between pages and
sharing information between requests, pages etc.
Advantages of JSP:
• vs. Active Server Pages (ASP): The advantages of JSP
are twofold. First, the dynamic part is written in Java,
not Visual Basic or other MS specific language, so it is
more powerful and easier to use. Second, it is
portable to other operating systems and non-
Microsoft Web servers.
• vs. Pure Servlets: It is more convenient to write (and
to modify!) regular HTML than to have plenty of
println statements that generate the HTML.
• vs. JavaScript: JavaScript can generate HTML
dynamically on the client but can hardly interact with
the web server to perform complex tasks like
database access and image processing etc.
• vs. Static HTML: Regular HTML, of course, cannot
contain dynamic information.
JSP - Architecture
• JSP page is translated into servlet by the help
of JSP translator.
• The JSP translator is a part of webserver that
is responsible to translate the JSP page into
servlet.
• After that Servlet page is compiled by the
compiler and gets converted into the class file.
• All the processes that happens in servlet is
performed on JSP later like initialization,
committing response to the browser and
destroy.
Life cycle of a JSP Page
• The JSP pages follows these phases:
• Translation of JSP Page
• Compilation of JSP Page
• Classloading (class file is loaded by the classloader)
• Instantiation (Object of the Generated Servlet is created).
• Initialization ( jspInit() method is invoked by the container).
• Reqeust processing ( _jspService() method is invoked by the
container).
• Destroy ( jspDestroy() method is invoked by the container).
• Note: jspInit(), jspService() and jspDestroy() are the life
cycle methods of JSP.
Directory structure of JSP
• The directory structure of JSP page is same as servlet.
We contains the jsp page outside the WEB-INF folder
or in any directory.
JSP API
The JSP API consists of two packages:
• javax.servlet.jsp
• javax.servlet.jsp.tagext
javax.servlet.jsp package
The javax.servlet.jsp package has two interfaces and classes.
The two interfaces are as follows:
• JspPage
• HttpJspPage
The classes are as follows:
• JspWriter
• PageContext
• JspFactory
• JspEngineInfo
• JspException
• JspError
The JspPage interface
• According to the JSP specification, all the generated servlet
classes must implement the JspPage interface.
• It extends the Servlet interface.
• It provides two life cycle methods.
Methods of JspPage interface
• public void jspInit(): It is invoked only once
during the life cycle of the JSP when JSP page
is requested firstly. It is used to perform
initialization. It is same as the init() method of
Servlet interface.
• public void jspDestroy(): It is invoked only
once during the life cycle of the JSP before the
JSP page is destroyed. It can be used to
perform some clean up operation.
The HttpJspPage interface
• The HttpJspPage interface provides the one
life cycle method of JSP. It extends the JspPage
interface.
Method of HttpJspPage interface:
• public void _jspService(): It is invoked each
time when request for the JSP page comes to
the container. It is used to process the
request.
• The underscore _ signifies that you cannot
override this method.
Important Questions
• Explain the directory structure of JSP.
• What is the advantage of using jsp.
• What is server side language.

You might also like