8/4/2019 JSP pres_314114
1/19
JSP Presentation TemplateJSP Presentation Template
8/4/2019 JSP pres_314114
2/19
CONTENTS OF PRESENTATIONCONTENTS OF PRESENTATION
JSP DEFINITIONJSP DEFINITION
JSP SERVERSJSP SERVERS
WHY WE LIKE JSP IN FIRST PLACEWHY WE LIKE JSP IN FIRST PLACE
HOW JSP WORKSHOW JSP WORKS
EXAMPLE OF JSPEXAMPLE OF JSP
COMPARISON OF JSP TO OTHER TECHNOLOGIESCOMPARISON OF JSP TO OTHER TECHNOLOGIES
COMPONENTS OF JSPCOMPONENTS OF JSP
JSP STANDARD ACTIONSJSP STANDARD ACTIONS
JSP SCRIPTING ELEMENTSJSP SCRIPTING ELEMENTS
JSP DIRECTIVE ELEMENTSJSP DIRECTIVE ELEMENTS
STANDARD ACTION TAGSSTANDARD ACTION TAGS
JSP LIFE CYCLE METHODSJSP LIFE CYCLE METHODS
IMPLICIT OBJECTSIMPLICIT OBJECTS
JSP CUSTOM TAGSJSP CUSTOM TAGS
ADVANTAGES AND CONSEQUENCESADVANTAGES AND CONSEQUENCES
WHAT IS IRRITATING ABOUT JSPWHAT IS IRRITATING ABOUT JSP
OVERVIEWOVERVIEW
8/4/2019 JSP pres_314114
3/19
JSP DEFINITION:JSP DEFINITION:
A textA text--based document capable of returning both static and dynamic contbased document capable of returning both static and dynamic content to aent to aclient browser.client browser.
Static content and dynamic content can be intermixed.Static content and dynamic content can be intermixed.
Static contentStatic content
HTML, XML, TextHTML, XML, Text
Dynamic contentDynamic content
Java codeJava code
Displaying properties of JavaBeansDisplaying properties of JavaBeans
Invoking business logic defined in Custom tagsInvoking business logic defined in Custom tags
JSP SERVERS:JSP SERVERS:
Blazix from DesiderataBlazix from Desiderata
Tomcat from ApacheTomcat from Apache
Weblogic from BEAWeblogic from BEA
WebSphere from IBMWebSphere from IBMAnd othersAnd others
8/4/2019 JSP pres_314114
4/19
Why we like JSP in the first place:Why we like JSP in the first place:
Open standard with support from many vendorsOpen standard with support from many vendors
The performance and scalability of servlets (for JSP pages compiThe performance and scalability of servlets (for JSP pages compile intole into
servlets)servlets)
Extensibility (custom tags)Extensibility (custom tags)
Easy integration with other J2EE and Java technologies (ServletsEasy integration with other J2EE and Java technologies (Servlets, EJB), EJB)
How JSP works:How JSP works:
8/4/2019 JSP pres_314114
5/19
When JSP servers needs to use a JSP page, it:When JSP servers needs to use a JSP page, it:
Translates the JSP into a Java servletTranslates the JSP into a Java servlet
Compiles the servletCompiles the servlet
Executes the servlet as normal Java codeExecutes the servlet as normal Java code
Hence, when you are writing JSP, you are writingHence, when you are writing JSP, you are writing higherhigher--levellevel Java codeJava code
You have two basic choices when using JSP:You have two basic choices when using JSP:
Let the JSP do all the work of a servletLet the JSP do all the work of a servlet Write a servlet that does the work and passes the results to JSPWrite a servlet that does the work and passes the results to JSP to create theto create the
resultant HTML pageresultant HTML page
This works because a servlet can call another servletThis works because a servlet can call another servlet
How JSP worksHow JSP works: (Continued): (Continued)
8/4/2019 JSP pres_314114
6/19
Example JSPExample JSP
Hello!Hello! The time is now The time is now
Notes:Notes:
TheThe tag is used, because we are computing atag is used, because we are computing a valuevalue andand
inserting it into the HTML.inserting it into the HTML.
8/4/2019 JSP pres_314114
7/19
Comparison of JSP toComparison of JSP toPHP Cold Fusion ASP JSP
Cost Free$0 (Express version)-
$5000 (Enterprise
version)
Free with Windows
NT, cost for 3rd-
party software
Free
Language In Page PHP CFML VBScript, JScript Java
OS PlatformUnix (Linux), Windows,
MacOS, OS/2
Windows NT, Solaris,
Linux
Windows 9x, NT,
other platforms
requires third-partyASP porting
products
UNIX, Microsoft
Windows, Mac OS,
Linux
Supported
Web server
iPlanet/Netscape
Enterprise Server
(NSAPI), MS InternetInformation Server (IIS),
Apache, Zeus, fhttpd, etc.
(ver 4)
IIS, Netscape
Enterprise Server ,
Apache, WebsiteServer (WSAPI), CGI
IIS, Personal Web
Server (PWS), other
servers with third-
party products
(ChiliSoft!)
Any Web server,
including Apache,
Netscape and IIS
8/4/2019 JSP pres_314114
8/19
Comparison of JSP toComparison of JSP to (Cont(Contd)d)
PHP ColdFusion ASP JSP
Supported
Database
MySQL, mSQL, ODBC,
Oracle, Informix, Sybase,
etc.
ODBC, OLE DB,
DB2, Oracle, Informix,
Sybase, etc.
any ODBC-
compliant database
any ODBC-
and
JDBC-compliant
database
Portability Fair (DB portability) Good Fair Good
Scalability Fair Good Good Good
Component
Support
COM, Java classes
(version 4)
COM, CORBA,
JavaBeansCOM components
JavaBeans,
Enterprise
JavaBeans
Learning curve High (C, Perl) Low Medium (VBScript,JScript) High (Java)
8/4/2019 JSP pres_314114
9/19
COMPONENTS OF JSP:COMPONENTS OF JSP:
JSP STANDARD ACTIONS:JSP STANDARD ACTIONS:
Standard actions are specific tags that affect the runtime behavStandard actions are specific tags that affect the runtime behavior of the JSPior of the JSPand affect the response sent back to the client.and affect the response sent back to the client.
EXAMPLE:EXAMPLE:
Here, Forwarding a request means that even the request object isHere, Forwarding a request means that even the request object is
forwarded to theforwarded to the
target page.target page.
8/4/2019 JSP pres_314114
10/19
JSP SCRIPTING Elements:JSP SCRIPTING Elements:
Scripting elements are used to include scripting code (Java codeScripting elements are used to include scripting code (Java code) within the JSP.) within the JSP.They allow to declare variables and methods, include arbitrary sThey allow to declare variables and methods, include arbitrary scripting code andcripting code andevaluate an expression. The three types of scripting element areevaluate an expression. The three types of scripting element are::
TheThe expressionexpression is evaluated and the result is inserted into the HTML pageis evaluated and the result is inserted into the HTML page
TheThecodecode is inserted into the servlet'sis inserted into the servlet's serviceservice methodmethod
IfIfcodecode contains declarations, they becomecontains declarations, they become locallocal variables of the servicevariables of the servicemethodmethod
This construction is called aThis construction is called a scriptletscriptlet
TheThedeclarationsdeclarations are inserted into the servletare inserted into the servlet class,class, not into a methodnot into a method Hence, declarations made here becomeHence, declarations made here become instanceinstance variablesvariables
8/4/2019 JSP pres_314114
11/19
JSP DIRECTIVE ELEMENTS:JSP DIRECTIVE ELEMENTS:
JSP Directives serve as messages to the JSP container from the JJSP Directives serve as messages to the JSP container from the JSP. They areSP. They areused to set global values such as class declaration, methods toused to set global values such as class declaration, methods to be implemented,be implemented,output content type, etc. All directives have scope of the entiroutput content type, etc. All directives have scope of the entire JSP file.e JSP file.
A directive is an option setting that affects how the servlet isA directive is an option setting that affects how the servlet is constructed from aconstructed from aJSP page.JSP page.
The three directives are Page, Include and Taglib.The three directives are Page, Include and Taglib.
TheThe PagePage directive can contain the list of all imported packages.directive can contain the list of all imported packages.
Example:Example:
Here, attribute can be import, contentType, errorPage, etc.Here, attribute can be import, contentType, errorPage, etc.
TheThe IncludeInclude directive is used to physically include the contents of anotherdirective is used to physically include the contents of another
file.file.
Example:Example:
8/4/2019 JSP pres_314114
12/19
Standard Action Tags:Standard Action Tags:
imports a JavaBeans component. imports a JavaBeans component.
gets a property value and adds it to the respo gets a property value and adds it to the response.nse.
sets a property value. sets a property value.
adds a parameter to a request. adds a parameter to a request.
generates the OBJECT or EMBED tag for an applet. generates the OBJECT or EMBED tag for an applet.
Terminates execution of current pageTerminates execution of current page
Forwards the call to a servlet or JSP page for service.Forwards the call to a servlet or JSP page for service.
Transfers control to the forwardeeTransfers control to the forwardee
Executes the specified pageExecutes the specified page
Includes the response from a servlet or JSP page that is calledIncludes the response from a servlet or JSP page that is called for the request.for the request.
Then returns control to the current pageThen returns control to the current page
8/4/2019 JSP pres_314114
13/19
JSP Lifecycle Methods:JSP Lifecycle Methods:
TheThejavax.servlet.jsp.JspPage interfacejavax.servlet.jsp.JspPage interface contains two methods:contains two methods:
1.1. public void jspInit()public void jspInit() --
This method is invoked when the JSP is initialized and theThis method is invoked when the JSP is initialized and the
page authors are free to provide initialization of the JSP by impage authors are free to provide initialization of the JSP by implementing thisplementing thismethod in their JSPs.method in their JSPs.
2.2. public void jspDestroy()public void jspDestroy() --
This method is invoked when the JSP is about to beThis method is invoked when the JSP is about to be
destroyed by the container. Similar to above, page authors can pdestroyed by the container. Similar to above, page authors can provide their ownrovide their ownimplementation.implementation.
The javax.servlet.jsp.HttpJspPage interfaceThe javax.servlet.jsp.HttpJspPage interface contains one method:contains one method:
public void _jspService(HttpServletRequest request, HttpServletRpublic void _jspService(HttpServletRequest request, HttpServletResponseesponseresponse) throws ServletException, IOExceptionresponse) throws ServletException, IOException
This method generated by the JSP container is invoked, every timThis method generated by the JSP container is invoked, every time a request comese a request comesto the JSP. The request is processed and the JSP generates approto the JSP. The request is processed and the JSP generates appropriate response.priate response.This response is taken by the container and passed back to the cThis response is taken by the container and passed back to the client.lient.
8/4/2019 JSP pres_314114
14/19
Implicit Objects:Implicit Objects:
JSP Implicit Objects are certain preJSP Implicit Objects are certain pre--defined variables that can be included in JSPdefined variables that can be included in JSP
expression and scriptlets and are only visible within the systemexpression and scriptlets and are only visible within the system
generated servicegenerated service
method.method.
Of the implicit objects, there are three most used implicit objeOf the implicit objects, there are three most used implicit objects that are used tocts that are used tohandle the current session , the incoming request, and the outghandle the current session , the incoming request, and the outgoing response. Theseoing response. These
three arethree are sessionsession,, requestrequest, and, and responseresponse respectively.respectively.
8/4/2019 JSP pres_314114
15/19
JSP CUSTOM TAGS:JSP CUSTOM TAGS:
Custom tags are userCustom tags are user--defined , redefined , re--usable tags that is used to perform repetitive tasksusable tags that is used to perform repetitive tasks
in a JSP page.in a JSP page.
It can be empty, can contain attributes, body or nest with anothIt can be empty, can contain attributes, body or nest with another tags.er tags.
A Tag Handler is a java class that implements the functionalityA Tag Handler is a java class that implements the functionality of a custom tag.of a custom tag.
A Tag Library Descriptor (TLD) file defines the functionality ofA Tag Library Descriptor (TLD) file defines the functionality of
a custom tag.a custom tag.
A Taglib element is the root element of a TLD file and it importA Taglib element is the root element of a TLD file and it imports a custom tag intos a custom tag into
current JSP page.current JSP page.
Tag Files: nature and purposeTag Files: nature and purpose
oo
Solve difficulty of reusing text/HTML within a tag.Solve difficulty of reusing text/HTML within a tag.
And makes it much easier to write simple tags, since you can doAnd makes it much easier to write simple tags, since you can do so in JSPso in JSP
instead of Java.instead of Java.oo
StandStand--alone file withalone file with
directive instead of traditionaldirective instead of traditional
directive.directive.
8/4/2019 JSP pres_314114
16/19
ADVANTAGES and CONSEQUENCES:ADVANTAGES and CONSEQUENCES:
AdvantagesAdvantages
EfficientEfficient
ConvenientConvenientServer engines typically haveServer engines typically have
builtbuilt--in infrastructures toin infrastructures to
handle parsing/decodinghandle parsing/decoding
HTML form data,HTML form data,reading/setting HTTP headers,reading/setting HTTP headers,
session trackingsession tracking
PowerfulPowerful
Java behind the sceneJava behind the scene
PortablePortable
Write once, run anywhereWrite once, run anywhere
InexpensiveInexpensiveVarious free or inexpensiveVarious free or inexpensive
engines availableengines available
ConsequencesConsequences
Need for a Server EngineNeed for a Server Engine
Another engine to maintainAnother engine to maintain UnUn--acceptably by the clientacceptably by the client
machinemachine
Virtual hosting of unrelatedVirtual hosting of unrelated
sites on a single machinesites on a single machinecan cause problems (choosecan cause problems (choose
your server engine wisely)your server engine wisely)
High Learning CurveHigh Learning Curve
Steeper learning curve thanSteeper learning curve than
Cold FusionCold Fusion
8/4/2019 JSP pres_314114
17/19
WhatWhats irritating about JSP?s irritating about JSP?
The tagThe tag--extension protocol is too complicatedextension protocol is too complicated
Also, tags donAlso, tags dont support certain kinds of code reuse.t support certain kinds of code reuse.
Also, Scriptlets complicate abstraction and code reuse.Also, Scriptlets complicate abstraction and code reuse.
8/4/2019 JSP pres_314114
18/19
JSP provide excellent server side scripting support for creatingJSP provide excellent server side scripting support for creating databasedatabasedriven dynamic web applications.driven dynamic web applications.
The Java is enclosed in special tags, such asThe Java is enclosed in special tags, such as ..
JSP files must have the extensionJSP files must have the extension
.jsp
.jspand it is secure, fast and independent ofand it is secure, fast and independent of
sever platforms.sever platforms.
Elements that are processed on server are Directives, ScriptingElements that are processed on server are Directives, Scripting and Actions.and Actions.
JSP lifecycle consists of two phase:JSP lifecycle consists of two phase: TRANSLATIONTRANSLATION
phase andphase and REQUESTREQUEST
PROCESSINGPROCESSING
phase.phase.
In Translation phase, JSP Code is translated into java servletsIn Translation phase, JSP Code is translated into java servlets which is thenwhich is then
compiled. It is done by the web container itself.compiled. It is done by the web container itself.
In Request processing phase, a response to the clients request iIn Request processing phase, a response to the clients request is been sent.s been sent.
JSP Life cycle methods are jspInit(), jspService() and jspDestroJSP Life cycle methods are jspInit(), jspService() and jspDestroy().y().
OVERVIEW OF JSP:OVERVIEW OF JSP:
8/4/2019 JSP pres_314114
19/19
Top Related