SlideShare a Scribd company logo
1 of 26
Download to read offline
Chapter 7
Being a JSP
A JSP is a servlet
How many times I’ve been accessed
Fully qualified class or Import
Questions
• Where each part of the JSP goes into the servlet code?
• May I ServletContext and ServletConfig?
• Type and syntax of the elements?
• Lifecycle?
Elements
• Scriptlet: <% %>
• Directive: <%@ %>
• Expression: <%= %>
• Declaration: <%! %>
Directives, Scriptlets & Expressions
Beware!
Expressions become arguments in out.print()
But JSPs are servlets
Declaration!
<%! int count=0; %>
Importing a variable
JSP Declatations
Instance
Variable
Local
Variable
Importing methods & variables
JSP lifecycle
• Look at the directives
• Create an HttpServlet subclass
• Writes
• Import statements
• Declaration statements
• Builds a service method _jspService()
• Combines all
Me Container, you
JSP
I will
• give you the class
• I might not show the generated Java
• look at your directives
• create an HttpServlet subclass
• Tomcat extends: org.apache.jasper.runtime.HttpJspBase
• write any imports or declarations statements in the class file,
• imports just below the package statement
• declarations below the class declaration and before the service method
• build the service method _jspService()
• called by the servlet superclass’ overridden service() method, and
• receives HttpServletRequest & HttpServletResponse.
• declare & initialize all implicit objects
• combine HTML, scriptlets & expressions into the service method
You should
• not worry on how I do the above
• Know how your elements work inside the generated servlet
• and what jspInit(), jspDestroy & _jspService() are about
Example
API and implicit objects
API and the generated servlet
Lifecycle of
a JSP
Initializing your
servlet JSP
Overwrite using declaration
Attributes in a JSP
Using
PageContext
Other (page) directives & attributes
<%@ page import=”foo.*” session=”false” %>
<%@ taglib tagdir=”/WEB-INF/tags/cool” prefix=”cool” %>
<%@ include file=”wickedHeader.html” %>
EL (Expression Language)
• Web page designers shouldn’t have to know Java.
• Java code in a JSP is hard to change and maintain.
We have a choice
One last word: Actions (details later)

More Related Content

What's hot

Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
Eleonora Ciceri
 
Shootout! template engines on the jvm
Shootout! template engines on the jvmShootout! template engines on the jvm
Shootout! template engines on the jvm
NLJUG
 

What's hot (19)

Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
 
Shootout! template engines on the jvm
Shootout! template engines on the jvmShootout! template engines on the jvm
Shootout! template engines on the jvm
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Jstl
JstlJstl
Jstl
 
Jsp
JspJsp
Jsp
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Angularjs & REST
Angularjs & RESTAngularjs & REST
Angularjs & REST
 
Alfresco Mvc - a seamless integration with Spring Mvc
Alfresco Mvc - a seamless integration with Spring MvcAlfresco Mvc - a seamless integration with Spring Mvc
Alfresco Mvc - a seamless integration with Spring Mvc
 
Jsp(java server pages)
Jsp(java server pages)Jsp(java server pages)
Jsp(java server pages)
 
JSP
JSPJSP
JSP
 

Viewers also liked

3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
Manolis Vavalis
 
1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
Manolis Vavalis
 
Ch. 10 custom tag development
Ch. 10 custom tag developmentCh. 10 custom tag development
Ch. 10 custom tag development
Manolis Vavalis
 

Viewers also liked (8)

Ch6 conversational state
Ch6   conversational stateCh6   conversational state
Ch6 conversational state
 
3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
 
1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
 
2η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
2η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού2η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
2η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
 
Ch. 12 security
Ch. 12 securityCh. 12 security
Ch. 12 security
 
Ch. x web performance
Ch. x web performanceCh. x web performance
Ch. x web performance
 
Ch. 10 custom tag development
Ch. 10 custom tag developmentCh. 10 custom tag development
Ch. 10 custom tag development
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to Ch. 7 beeing a jsp

Core web application development
Core web application developmentCore web application development
Core web application development
Bahaa Farouk
 

Similar to Ch. 7 beeing a jsp (20)

Core web application development
Core web application developmentCore web application development
Core web application development
 
Jsp
JspJsp
Jsp
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
JSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSJSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODS
 
Jsp 01
Jsp 01Jsp 01
Jsp 01
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
 
JavaScript, often abbreviated as JS, is a programming language and core techn...
JavaScript, often abbreviated as JS, is a programming language and core techn...JavaScript, often abbreviated as JS, is a programming language and core techn...
JavaScript, often abbreviated as JS, is a programming language and core techn...
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Advance java session 9
Advance java session 9Advance java session 9
Advance java session 9
 
Jsp & struts
Jsp & strutsJsp & struts
Jsp & struts
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
SCWCD : Java server pages CHAP : 9
SCWCD : Java server pages  CHAP : 9SCWCD : Java server pages  CHAP : 9
SCWCD : Java server pages CHAP : 9
 

Recently uploaded

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

Ch. 7 beeing a jsp