You are on page 1of 4

Jsp (java server pages)

Why jsp?
In early days web applications are static and they are created with the help of one
or more html pages.
Late there is requirement came for dynamic web applications and to develop
dynamic pages a first server side web technology was released with the name CGI
technology (common gateway interface)
With CGI technology there are two major problems identified as it increases burden
on server and it is not a secure technology
Later sun Microsystems released servlet technology for creating dynamic web
applications.
Servlet technology provides less burden and it is secure technology but developer
should write a very large amount of java code for creating the application logics
Microsoft introduced a technology called ASP (Active server pages) with a set of
predefined tags and a small amount of VB script code, for developing dynamic web
applications
Industry developers attracted for ASP due to less amount of code for dev eloping
web applications
Again to migrate developers from Microsoft technology to Sun Microsystems , sun
people introduced a second server side technology for creating web applications
with name JSP
Definition:- Java Server Pages (JSP) is a Java technology that allows software
developers to generate the dynamic web content

Differences between Servlet and JSP


Sl.N
O
1

Servlets

Jsp

servlet is a java class so if any


changes are done in a servlet
then it must be recompile,
reloaded and then server should
be restarted it is time consuming
work
servlet technology has not given
any technique for seperating
business logic and presentation

Jsp's are pages so we can directly open


the page in server and
we can modify it.
there is need to recompile, reload and
restart the server
Jsp technology has given a way to
seperating
business logic and presentation logic so

4
5

logic so both logics can not


be developed parallely
in servlet there only three
implicit objects called
config,request and response
in servlets there are 3 scopes
request,session,context
in servlet technoly we can create
servlets in protocol independent
manner
In a servlet, by default sessions
are not activated so
a servlet will not recognise the
client

both logics can be developed parallely


in Jsp there nine implicit objects called
config,request and
in Jsp there are 4 scopes page,
request,session,context
An Jps page will only handle http protocol
so, it is a protocol dependent
In Jsp, by default session are activated so
a Jps page recognizes the client

Jsp Translation:
each jsp page will be translated into a servlet in server
A jsp execution in server has two phases
1. translation phase
2.execution phase
in translation pahase, first a jsp page iwll be converted to equivalent servlet and
then a servlet will be compiled.
in execution phase. object is created for a servlet then it is initialized then finally
service() is executed
in translation phase a jsp container(we container) will uses a page compiler for
converting a jsp page into a servlet then a java compiler for converting .class file

.jsp.java.class
A Jsp container will execute translation phase then followed by execution phase,
when first request is sent to jsp page and when a jsp page modified. In other
request only service is executed
When a first request arrived to a JSP

Jsp
life

cycle methods:
Jsp life cycle methods looks like servlet life cycle methods only
Life cycle methods of jsp page are given in javax.servlet.jsp.HttpJspPage interface.
HttpJspPage extends javax.servlet.jsp.JspPage interface.
In JspPage interface, 3 life cycle methods of jsp are given
1.jspInit()
2.jspDestroy()
In HttpJspPage interface , one more life cycle method of jsp is given called
_jspService().
Life cycle methods of jsp page are:
1.jspInit()
2.jspDestroy()
3._jspService(request,response).
When a jsp page is translated into an equivalent servlet class, that servlet class
indirectly implements HttpJspPage interface
At the time of translating a jsp page, a container extends the servlet calss from a
super class. That super class extends HttpServlet and implements HttpJspPage
interface
Ex:

In case of tomcat container extends internal servlet class of jsp page from a super
class HttpJspBase and it extends HttpServlet and implements HttpJspPage interface

You might also like