SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Slide 1 of 20
Introduction to JSP
Slide 2 of 20
Objectives
 JSP
 Benefits of JSP
 JSP Request – Response Cycle
 Servlet – JSP
 JSP Life Cycle
 Elements / Tags of JSP
 Implicit Objects
Slide 3 of 20
JSP
 Java Server Page (JSP) is a server side script
language
 Saved with .jsp extension
 A simple, yet powerful Java technology for
creating and maintaining dynamic-content webs
pages
 JSP page are converted by the web container
into a Servlet instance
 It focus on the presentation logic of the web
application
Slide 4 of 20
Benefits of JSP
 Segregation of the work profiles of a Web
designer and a Web developer
 Emphasizing Reusable Components
 Simplified Page Development
Slide 5 of 20
JSP Request-Response Cycle
Slide 6 of 30
Servlet - JSP
Servlet JSP
HTML Code inside Java Java Code inside HTML
Extensive Coding Less Coding
Saved with .java Saved with .jsp
Designed for Business Logic Designed for Presentation Logic
Any changes are made to the html
code, then necessary to compile and
test the HTML code
No need to compile again and again to
obtain the required changes.
Manual Compilation is required to
changes made to any files
Automatically incorporates changes made
to any files
Slide 7 of 20
JSP Life Cycle
Translation
Compilation
Execution
Slide 8 of 30
Elements / Tags of JSP
 Types of Tags
– Scripting-oriented tags
– XML-based tags
Elements / Tags Syntax
Comments <%-- --%>
Directives <%@ %>
Declarations <%! %>
Expression <%= %>
Scriptlet <% %>
Actions <jsp: />, <jsp: > </jsp: >
Slide 9 of 30
Page Directives
 Defines attributes that notify the JSP engine about the
general settings of a JSP page
– <%@page attribute1=“value” attribute2=“value” %>
– <jsp:directive.page attribute1=“value” attribute2=“value” />
Attribute Default Value Examples
language “java” “java”
contentType “text/htm” contentType=“text/html”
contentType=“text/xml”
extends None extends=“com.Login”
import None import=“java.util.Vector,
java.sql.*”
Slide 10 of 30
Page Directives
Attribute Default Value Examples
session “true” session=“false”
info None info=“Registration Form”
buffer “8kb” Buffer=“12kb”
Buffer=“false”
autoFlush “true” autoFlush=“true”
isThreadSafe “true” isThreadSafe=“false”
errorPage None errorPage=“results/error.jsp
”
isErrorPage “false” isErrorPage=“true”
Slide 11 of 20
Include / Taglib Directory
 Include directory is used to include contents of
one file in another.
– <%@include file=“footer.jsp” %>
– <jsp:directive.include file=“footer.jsp” />
 Taglib directory is used custom tag
– <%@taglib uri=“ATMTag.tld” prefix=“atm” %>
– <jsp:directive.taglib uri=“ATMTag.tld”
prefix=“atm” />
Slide 12 of 30
Implicit Objects
Object Class / Interface
page javax.servlet.jsp.HttpJspPage
config javax.servlet.ServletConfig
request javax.servlet.http.HttpServletRequest
response javax.servlet.http.HttpServletResponse
out javax.servlet.jsp.JspWriter
session javax.servlet.http.HttpSession
application javax.servlet.ServletContext
pageContext javax.servlet.jsp.PageContext
exception java.lang.Throwable
Slide 13 of 20
Action Tags / Elements
 Forward
 Include
 Plug-in
 Bean tags
Slide 14 of 20
Forward
 To permanently transfer control from a JSP page
to another location on the local server
– <jsp:forward page=“/user/UserHome.jsp” />
– <jsp:forward page=“/user/ChangePassword.jsp”>
• <jsp:param name=“UserId” value=“common” />
– </jsp:forward>
Slide 15 of 20
Include
 To incorporate the content or insert a file from
another page into current page
– <jsp:include page=“ChangePwd.jsp” flush=“true” />
– <jsp:include page=“ChangePwd.jsp” flush=“true”>
<jsp:param name=“UserId” value=“common” />
– </jsp:include>
 The include directive inserts the file at the time
the JSP page is translated into a Servlet
 The include action inserts the file at the time
the page is requested
Slide 16 of 20
Plug-in
– The <jsp:plugin> action is used to generate browser-
specific HTML for specifying Java applets which rely
on Sun Microsystem’s Java plug-in
<jsp:plugin type=“applet” code=“test.AppletTest”
codebase=“/classes/applets” height=“150” width=“100”>
<jsp:params>
<jsp:param name=“color” value=“blue” />
<jsp:param name=“speed” value=“fast” />
</jsp:params>
<jsp:fallback> Your browser can’t display this applet text </jsp:fallback>
</jsp:plugin>
Slide 17 of 20
Java Bean
Slide 18 of 20
Bean Tags
– <jsp:useBean /> action tag is used to create a
reference and include an existing bean component
in JSP
– <jsp:useBean id=“myCar” class=“cars.CarBean”
scope=“page | request | session | application” />
– <jsp:setProperty name=“myCar” property=“make”
value=“Ford” />
– <jsp:setProperty name=“myCar” property=“make”
param=“txtMake” />
– <jsp:getProperty name=“myCar”
property=“make” />
Slide 19 of 20
Summary
 JSP
 Benefits of JSP
 JSP Request – Response Cycle
 JSP Life Cycle
 Elements / Tags of JSP
– Comments
– Directives
– Declarations
– Expression
– Scriptlet
Slide 20 of 20
Summary
 Implicit Objects
 Action Tags
– Forward
– Include
– Plug-in
– Bean Tags

Weitere ähnliche Inhalte

Was ist angesagt?

Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng
 

Was ist angesagt? (20)

Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
 
JSP
JSPJSP
JSP
 
Jsp Slides
Jsp SlidesJsp Slides
Jsp Slides
 
Jsp element
Jsp elementJsp element
Jsp element
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Introduction to single page application with angular js
Introduction to single page application with angular jsIntroduction to single page application with angular js
Introduction to single page application with angular js
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
 
Hastening React SSR - Web Performance San Diego
Hastening React SSR - Web Performance San DiegoHastening React SSR - Web Performance San Diego
Hastening React SSR - Web Performance San Diego
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10
 
Mule esb
Mule esbMule esb
Mule esb
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
Drupal 8 override: services and plugins
Drupal 8 override: services and pluginsDrupal 8 override: services and plugins
Drupal 8 override: services and plugins
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
Java Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsJava Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 Basics
 

Ähnlich wie Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech

3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
shiva404
 

Ähnlich wie Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech (20)

JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Introduction to JSP pages
Introduction to JSP pagesIntroduction to JSP pages
Introduction to JSP pages
 
Jsp servlets
Jsp servletsJsp servlets
Jsp servlets
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Introduction to jsp
Introduction to jspIntroduction to jsp
Introduction to jsp
 
Introduction to jsp
Introduction to jspIntroduction to jsp
Introduction to jsp
 
J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 

Mehr von MasterCode.vn

Pd fbuoi7 8--tongquanseo-mastercode.vn
Pd fbuoi7 8--tongquanseo-mastercode.vnPd fbuoi7 8--tongquanseo-mastercode.vn
Pd fbuoi7 8--tongquanseo-mastercode.vn
MasterCode.vn
 
Pd fbuoi5 6-ảnh hưởng của social media tới kết quả seo-mastercode.vn
Pd fbuoi5 6-ảnh hưởng của social media tới kết quả seo-mastercode.vnPd fbuoi5 6-ảnh hưởng của social media tới kết quả seo-mastercode.vn
Pd fbuoi5 6-ảnh hưởng của social media tới kết quả seo-mastercode.vn
MasterCode.vn
 
Pdf buoi3 4-link-building-tran-ngoc-chinh-mastercode.vn
Pdf buoi3 4-link-building-tran-ngoc-chinh-mastercode.vnPdf buoi3 4-link-building-tran-ngoc-chinh-mastercode.vn
Pdf buoi3 4-link-building-tran-ngoc-chinh-mastercode.vn
MasterCode.vn
 
Pd fbuoi3 4-kỹ thuật xây dựng back link-mastercode.vn
Pd fbuoi3 4-kỹ thuật xây dựng back link-mastercode.vnPd fbuoi3 4-kỹ thuật xây dựng back link-mastercode.vn
Pd fbuoi3 4-kỹ thuật xây dựng back link-mastercode.vn
MasterCode.vn
 

Mehr von MasterCode.vn (20)

Pd ftai lieu-tieng-anh-cho-nguoi-moi-bat-dau-mastercode.vn
Pd ftai lieu-tieng-anh-cho-nguoi-moi-bat-dau-mastercode.vnPd ftai lieu-tieng-anh-cho-nguoi-moi-bat-dau-mastercode.vn
Pd ftai lieu-tieng-anh-cho-nguoi-moi-bat-dau-mastercode.vn
 
Why apps-succeed-wpr-mastercode.vn
Why apps-succeed-wpr-mastercode.vnWhy apps-succeed-wpr-mastercode.vn
Why apps-succeed-wpr-mastercode.vn
 
Dzone performancemonitoring2016-mastercode.vn
Dzone performancemonitoring2016-mastercode.vnDzone performancemonitoring2016-mastercode.vn
Dzone performancemonitoring2016-mastercode.vn
 
Google công bố thông tin lịch xu hướng ngành 2017 mastercode.vn
Google công bố thông tin lịch xu hướng ngành 2017 mastercode.vnGoogle công bố thông tin lịch xu hướng ngành 2017 mastercode.vn
Google công bố thông tin lịch xu hướng ngành 2017 mastercode.vn
 
Nghiên cứu về khách hàng mastercode.vn
Nghiên cứu về khách hàng mastercode.vnNghiên cứu về khách hàng mastercode.vn
Nghiên cứu về khách hàng mastercode.vn
 
Lập trình sáng tạo creative computing textbook mastercode.vn
Lập trình sáng tạo creative computing textbook mastercode.vnLập trình sáng tạo creative computing textbook mastercode.vn
Lập trình sáng tạo creative computing textbook mastercode.vn
 
Pd fbuoi7 8--tongquanseo-mastercode.vn
Pd fbuoi7 8--tongquanseo-mastercode.vnPd fbuoi7 8--tongquanseo-mastercode.vn
Pd fbuoi7 8--tongquanseo-mastercode.vn
 
Pd fbuoi5 6-ảnh hưởng của social media tới kết quả seo-mastercode.vn
Pd fbuoi5 6-ảnh hưởng của social media tới kết quả seo-mastercode.vnPd fbuoi5 6-ảnh hưởng của social media tới kết quả seo-mastercode.vn
Pd fbuoi5 6-ảnh hưởng của social media tới kết quả seo-mastercode.vn
 
Pdf buoi3 4-link-building-tran-ngoc-chinh-mastercode.vn
Pdf buoi3 4-link-building-tran-ngoc-chinh-mastercode.vnPdf buoi3 4-link-building-tran-ngoc-chinh-mastercode.vn
Pdf buoi3 4-link-building-tran-ngoc-chinh-mastercode.vn
 
Pd fbuoi3 4-kỹ thuật xây dựng back link-mastercode.vn
Pd fbuoi3 4-kỹ thuật xây dựng back link-mastercode.vnPd fbuoi3 4-kỹ thuật xây dựng back link-mastercode.vn
Pd fbuoi3 4-kỹ thuật xây dựng back link-mastercode.vn
 
Pd fbuoi2 onpage – tối ưu hóa trang web-mastercode.vn
Pd fbuoi2 onpage – tối ưu hóa trang web-mastercode.vnPd fbuoi2 onpage – tối ưu hóa trang web-mastercode.vn
Pd fbuoi2 onpage – tối ưu hóa trang web-mastercode.vn
 
Pd fbuoi1 giới thiệu seo tools cơ bản-seo manager + seo guy-mastercode.vn
Pd fbuoi1 giới thiệu seo tools cơ bản-seo manager + seo guy-mastercode.vnPd fbuoi1 giới thiệu seo tools cơ bản-seo manager + seo guy-mastercode.vn
Pd fbuoi1 giới thiệu seo tools cơ bản-seo manager + seo guy-mastercode.vn
 
Pdf buoi1 2-on-page-tran-ngoc-chinh-mastercode.vn
Pdf buoi1 2-on-page-tran-ngoc-chinh-mastercode.vnPdf buoi1 2-on-page-tran-ngoc-chinh-mastercode.vn
Pdf buoi1 2-on-page-tran-ngoc-chinh-mastercode.vn
 
Pdfbài 7 máy tính xác tay và máy in bảo trì sự cố máy tính-mastercode.vn
Pdfbài 7 máy tính xác tay và máy in   bảo trì sự cố máy tính-mastercode.vnPdfbài 7 máy tính xác tay và máy in   bảo trì sự cố máy tính-mastercode.vn
Pdfbài 7 máy tính xác tay và máy in bảo trì sự cố máy tính-mastercode.vn
 
Pdfbài 6 bảo trì máy tính bảo trì sự cố máy tính-mastercode.vn
Pdfbài 6 bảo trì máy tính   bảo trì sự cố máy tính-mastercode.vnPdfbài 6 bảo trì máy tính   bảo trì sự cố máy tính-mastercode.vn
Pdfbài 6 bảo trì máy tính bảo trì sự cố máy tính-mastercode.vn
 
Pdfbài 5 bảo trì và tối ưu windows bảo trì sự cố máy tính-mastercode.vn
Pdfbài 5 bảo trì và tối ưu windows   bảo trì sự cố máy tính-mastercode.vnPdfbài 5 bảo trì và tối ưu windows   bảo trì sự cố máy tính-mastercode.vn
Pdfbài 5 bảo trì và tối ưu windows bảo trì sự cố máy tính-mastercode.vn
 
Pdfbài 4 ổ cứng hard drive bảo trì sự cố máy tính-mastercode.vn
Pdfbài 4 ổ cứng hard drive   bảo trì sự cố máy tính-mastercode.vnPdfbài 4 ổ cứng hard drive   bảo trì sự cố máy tính-mastercode.vn
Pdfbài 4 ổ cứng hard drive bảo trì sự cố máy tính-mastercode.vn
 
Pdfbài 3 cpu và ram bảo trì sự cố máy tính-mastercode.vn
Pdfbài 3 cpu và ram   bảo trì sự cố máy tính-mastercode.vnPdfbài 3 cpu và ram   bảo trì sự cố máy tính-mastercode.vn
Pdfbài 3 cpu và ram bảo trì sự cố máy tính-mastercode.vn
 
Pdfbài 1 giới thiệu chung về phần cứng bảo trì sự cố máy tính-mastercode.vn
Pdfbài 1 giới thiệu chung về phần cứng   bảo trì sự cố máy tính-mastercode.vnPdfbài 1 giới thiệu chung về phần cứng   bảo trì sự cố máy tính-mastercode.vn
Pdfbài 1 giới thiệu chung về phần cứng bảo trì sự cố máy tính-mastercode.vn
 
Pdfbài 2 bo mạch chủ (main) bảo trì sự cố máy tính-mastercode.vn
Pdfbài 2 bo mạch chủ (main)   bảo trì sự cố máy tính-mastercode.vnPdfbài 2 bo mạch chủ (main)   bảo trì sự cố máy tính-mastercode.vn
Pdfbài 2 bo mạch chủ (main) bảo trì sự cố máy tính-mastercode.vn
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech

  • 1. Slide 1 of 20 Introduction to JSP
  • 2. Slide 2 of 20 Objectives  JSP  Benefits of JSP  JSP Request – Response Cycle  Servlet – JSP  JSP Life Cycle  Elements / Tags of JSP  Implicit Objects
  • 3. Slide 3 of 20 JSP  Java Server Page (JSP) is a server side script language  Saved with .jsp extension  A simple, yet powerful Java technology for creating and maintaining dynamic-content webs pages  JSP page are converted by the web container into a Servlet instance  It focus on the presentation logic of the web application
  • 4. Slide 4 of 20 Benefits of JSP  Segregation of the work profiles of a Web designer and a Web developer  Emphasizing Reusable Components  Simplified Page Development
  • 5. Slide 5 of 20 JSP Request-Response Cycle
  • 6. Slide 6 of 30 Servlet - JSP Servlet JSP HTML Code inside Java Java Code inside HTML Extensive Coding Less Coding Saved with .java Saved with .jsp Designed for Business Logic Designed for Presentation Logic Any changes are made to the html code, then necessary to compile and test the HTML code No need to compile again and again to obtain the required changes. Manual Compilation is required to changes made to any files Automatically incorporates changes made to any files
  • 7. Slide 7 of 20 JSP Life Cycle Translation Compilation Execution
  • 8. Slide 8 of 30 Elements / Tags of JSP  Types of Tags – Scripting-oriented tags – XML-based tags Elements / Tags Syntax Comments <%-- --%> Directives <%@ %> Declarations <%! %> Expression <%= %> Scriptlet <% %> Actions <jsp: />, <jsp: > </jsp: >
  • 9. Slide 9 of 30 Page Directives  Defines attributes that notify the JSP engine about the general settings of a JSP page – <%@page attribute1=“value” attribute2=“value” %> – <jsp:directive.page attribute1=“value” attribute2=“value” /> Attribute Default Value Examples language “java” “java” contentType “text/htm” contentType=“text/html” contentType=“text/xml” extends None extends=“com.Login” import None import=“java.util.Vector, java.sql.*”
  • 10. Slide 10 of 30 Page Directives Attribute Default Value Examples session “true” session=“false” info None info=“Registration Form” buffer “8kb” Buffer=“12kb” Buffer=“false” autoFlush “true” autoFlush=“true” isThreadSafe “true” isThreadSafe=“false” errorPage None errorPage=“results/error.jsp ” isErrorPage “false” isErrorPage=“true”
  • 11. Slide 11 of 20 Include / Taglib Directory  Include directory is used to include contents of one file in another. – <%@include file=“footer.jsp” %> – <jsp:directive.include file=“footer.jsp” />  Taglib directory is used custom tag – <%@taglib uri=“ATMTag.tld” prefix=“atm” %> – <jsp:directive.taglib uri=“ATMTag.tld” prefix=“atm” />
  • 12. Slide 12 of 30 Implicit Objects Object Class / Interface page javax.servlet.jsp.HttpJspPage config javax.servlet.ServletConfig request javax.servlet.http.HttpServletRequest response javax.servlet.http.HttpServletResponse out javax.servlet.jsp.JspWriter session javax.servlet.http.HttpSession application javax.servlet.ServletContext pageContext javax.servlet.jsp.PageContext exception java.lang.Throwable
  • 13. Slide 13 of 20 Action Tags / Elements  Forward  Include  Plug-in  Bean tags
  • 14. Slide 14 of 20 Forward  To permanently transfer control from a JSP page to another location on the local server – <jsp:forward page=“/user/UserHome.jsp” /> – <jsp:forward page=“/user/ChangePassword.jsp”> • <jsp:param name=“UserId” value=“common” /> – </jsp:forward>
  • 15. Slide 15 of 20 Include  To incorporate the content or insert a file from another page into current page – <jsp:include page=“ChangePwd.jsp” flush=“true” /> – <jsp:include page=“ChangePwd.jsp” flush=“true”> <jsp:param name=“UserId” value=“common” /> – </jsp:include>  The include directive inserts the file at the time the JSP page is translated into a Servlet  The include action inserts the file at the time the page is requested
  • 16. Slide 16 of 20 Plug-in – The <jsp:plugin> action is used to generate browser- specific HTML for specifying Java applets which rely on Sun Microsystem’s Java plug-in <jsp:plugin type=“applet” code=“test.AppletTest” codebase=“/classes/applets” height=“150” width=“100”> <jsp:params> <jsp:param name=“color” value=“blue” /> <jsp:param name=“speed” value=“fast” /> </jsp:params> <jsp:fallback> Your browser can’t display this applet text </jsp:fallback> </jsp:plugin>
  • 17. Slide 17 of 20 Java Bean
  • 18. Slide 18 of 20 Bean Tags – <jsp:useBean /> action tag is used to create a reference and include an existing bean component in JSP – <jsp:useBean id=“myCar” class=“cars.CarBean” scope=“page | request | session | application” /> – <jsp:setProperty name=“myCar” property=“make” value=“Ford” /> – <jsp:setProperty name=“myCar” property=“make” param=“txtMake” /> – <jsp:getProperty name=“myCar” property=“make” />
  • 19. Slide 19 of 20 Summary  JSP  Benefits of JSP  JSP Request – Response Cycle  JSP Life Cycle  Elements / Tags of JSP – Comments – Directives – Declarations – Expression – Scriptlet
  • 20. Slide 20 of 20 Summary  Implicit Objects  Action Tags – Forward – Include – Plug-in – Bean Tags