SlideShare a Scribd company logo
1 of 24
U18CSI6201
INTERNET & WEB PROGRAMMING
JSP
V.SENTHIL KUMAR
Department of CSE
COURSE
OUTCOMES
CO1: DESIGN A WEBSITE USING HTML (K5, S3)
CO2: Apply Cascading Style Sheet to design a HTML
Webpage (K3, S2)
CO3: Develop a HTML form and validate it using Java
Script (K5, S2)
CO4: Develop web application using JSP, Servlet (K5,
S3)
CO5: Develop an XML document and validate it using
SCHEMA (K5, S2)
AGENDA
WHAT & WHY
JSP?
SERVLET VS JSP JSP ELEMENTS JSP/SERVLETS IN
THE ENTERPRISE
USING JAVA
BEANS IN JSP
TAG LIBRARIES
AND TAG TYPES
What and
Why of JSP?
• JSP = Java code imbedded
in HTML or XML
• Static portion of the
page is HTML
• Dynamic portion is Java
• Easy way to develop and
maintain dynamic web
pages and dynamic XML
documents
Servlet vs.
JSP
• Servlet Example
Servlet vs.
JSP
Recommendation
• Use JSP
• If presentation changes frequently
• Presentation is complex
• Use Servlets
• Validation, simple business logic
• Simple/small presentation
Anatomy of a JSP Page
• Template (static HTML or XML)
• JSP Elements
• Tag libraries
Element Type JSP Syntax Description
Directives <%@ directive_name%> Controls to define translation into Java code
Scripting <% …………… %> Embed Java code in HTML
Actions <jsp: …………. > JSP-specific tag for Java Beans
JSP Elements
JSP Elements
Accessing
Servlet
Variables
• config
• request
• response
• session
• out
• pageContext
• application
• page
JSP Elements:Servlet Variables
Simplify JSP Development
Use Java Beans
Use Tag Libraries
Model/View/Controller
JavaBean
Request object
JSP/Servlets in the Enterprise
Servlet
JSP
page
Data
base
Web
Server
Model
One
Architecture
Output
doGet/
doPost
Input
<<forward>>
<<creates>>
<<uses>>
Using Java Beans in JSP
Model 1
<HTML>
<HEAD><TITLE>JSP Page 2</TITLE></HEAD>
<BODY>
….
<jsp:useBean id=“employee” class=“javaBeans.Employee” scope=“request” />
....
<br>lastname = <jsp:getProperty name=“employee” property=“lastName” />
<br>firstname = <jsp:getProperty name=“employee” property=“firstName” />
<br>lastname = <%= employee.getLastName() %>
<br>firstname = <%= employee.getFirstName() %>
….
</BODY>
</HTML>
Getting values from a java bean
Get Java Bean
Reference
Java Bean
class variables
Using Java Beans in JSP
Model 1
<HTML>
<HEAD><TITLE>JSP Page 1</TITLE></HEAD>
<BODY>
….
<jsp:useBean id=“customer1” class=“control.Customer” scope=“request”>
<jsp:setProperty name=“customer1” property=“lastName” value=“Flintstone”
/>
<jsp:setProperty name=“customer1” property=“firstName” value=“Wilma” />
<% customer1.setUserid(“flintstonew”); %>
<% customer1.setPassword(“dino”); %>
</jsp:useBean>
….
<jsp:forward page=”/jspPage2” />”/>
….
</BODY>
</HTML>
Creating a java bean and setting values in the java bean
Create
Java Bean
Forward
request to
next JSP page
Using Java Beans in JSP
Model 1
<HTML>
<HEAD><TITLE>JSP Page 2</TITLE></HEAD>
<BODY>
….
<jsp:useBean id=“customer1” class=“control.Customer” scope=“request” />
....
<br>Last name = <jsp:getProperty name=“customer1” property=“lastName” />
<br>first name = <jsp:getProperty name=“customer1” property=“firstName” />
<br>Username = <% customer1.getUserid(); %>
<br>Password = <% customer1.getPassword(); %>
….
</BODY>
</HTML>
Getting values from a java bean
Get Java Bean
Reference
Java Bean
class variables
Tag Libraries
• Create custom XML tags that you
can imbed in JSP pages
• Custom commands (i.e., macros)
• Java tag handler class defined for each
custom tag
• XML tag in JSP  Java method called
for tag
Tag Types
• XML format
• Tag without a body
<rkjTagLib:deptHeader/>
• Tag without a body but with an attribute
<rkjTagLib:table rowcount=5 colcount=3 />
• Tag with body and an attribute
<rkjTagLib:table rowcount=5 colcount=3 >
Title of Table
</rkjTagLIb:table>
Tag Handler Class
import java.io.*;
import java.servlet.jsp.*;
import java.servlet.jsp.tagext.*;
public class DeptHeader extends TagSupport
{
public int doStartTag()
{
try
{
JspWriter out = pageContext.getOut();
out.println(“<H2>Information Systems Dept.</H1>”);
out.println(“<H3>Brigham Young University-Idaho </H3>”);
}
catch (IOException ioex)
{
….
}
return (SKIP_BODY);
}
public int doEndTag()
{
return(EVAL_PAGE);
}
}
Inherit TagSupport
Invoked at
starting tag
Invoked at
ending tag
Tag Library Descriptor
<?xml version=“1.0” encoding=“ISO-8859-1” ?>
<!DOCTYPE taglib PUBLIC
“-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN”
http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd>
<taglib>
<tlib-version>1.0</tlib-version>>
<jspversion>1.2</jspversion>
<shortname>homeDirectBank</shortname>
<tag>
<name>deptHeader</name>
<tagclass>homedirectbank.DeptHeader</tagclass>
<bodycontent>EMPTY</bodycontent>
<info>Inserts IS department header</info>
</tag>
</taglib>
Using Tag in JSP Page
<taglib>
<tlibversion>1.1</tlibversion>
<jspversion>1.2</jspversion>
<shortname>homeDirectBank</shortname>
<tag>
<name>deptHeader</name>
<tagclass>com.taglib.homedirectbank.DeptHeader</tagclass>
<bodycontent>EMPTY</bodycontent>
<info>Inserts IS department header</info>
</tag>
</taglib>
Tag Library Descriptor (homeDrectBank)
<%@ taglib uri=“/homeDirectBank”
prefix=“utils”>
<HTML>
<HEAD><TITLE>Test Servlet</TITLE></HEAD>
<BODY>
<utils:deptHeader />
…..
…..
</BODY>
</HTML>
}
JSP Page
import java.io.*;
import java.servlet.jsp.*;
import java.servlet.jsp.tagext.*;
public class DepHeader extends TagSupport
{
public int doStartTag()
{
try
{
JspWriter out = pageContext.getOut();
out.println(“<H2>Information Systems Dept.</H1>”);
out.println(“<H3>Brigham Young University-Idaho </H3>”);
}
catch (IOException ioex)
{
….
}
return (SKIP_BODY);
}
public int doEndTag()
{
return(EVAL_PAGE);
}
}
Tag Handler Class
maps
uses

More Related Content

Similar to JSP.pptx

JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGESKalpana T
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
Spring MVC
Spring MVCSpring MVC
Spring MVCyuvalb
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)Talha Ocakçı
 
SharePoint 2010 Content Query Web Part
SharePoint 2010 Content Query Web PartSharePoint 2010 Content Query Web Part
SharePoint 2010 Content Query Web PartKim Frehe
 
JSP - Part 2 (Final)
JSP - Part 2 (Final) JSP - Part 2 (Final)
JSP - Part 2 (Final) Hitesh-Java
 
15 expression-language
15 expression-language15 expression-language
15 expression-languagesnopteck
 
Session 36 - JSP - Part 1
Session 36 - JSP - Part 1Session 36 - JSP - Part 1
Session 36 - JSP - Part 1PawanMM
 
Java EE7 Demystified
Java EE7 DemystifiedJava EE7 Demystified
Java EE7 DemystifiedAnkara JUG
 
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012crokitta
 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsVinícius de Moraes
 
Session 37 - JSP - Part 2 (final)
Session 37 - JSP - Part 2 (final)Session 37 - JSP - Part 2 (final)
Session 37 - JSP - Part 2 (final)PawanMM
 

Similar to JSP.pptx (20)

Java .ppt
Java .pptJava .ppt
Java .ppt
 
25.ppt
25.ppt25.ppt
25.ppt
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
SharePoint 2010 Content Query Web Part
SharePoint 2010 Content Query Web PartSharePoint 2010 Content Query Web Part
SharePoint 2010 Content Query Web Part
 
JSP - Part 2 (Final)
JSP - Part 2 (Final) JSP - Part 2 (Final)
JSP - Part 2 (Final)
 
15 expression-language
15 expression-language15 expression-language
15 expression-language
 
WEB TECHNOLOGIES JSP
WEB TECHNOLOGIES  JSPWEB TECHNOLOGIES  JSP
WEB TECHNOLOGIES JSP
 
Apex & jQuery Mobile
Apex & jQuery MobileApex & jQuery Mobile
Apex & jQuery Mobile
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
14 mvc
14 mvc14 mvc
14 mvc
 
Session 36 - JSP - Part 1
Session 36 - JSP - Part 1Session 36 - JSP - Part 1
Session 36 - JSP - Part 1
 
Java EE7 Demystified
Java EE7 DemystifiedJava EE7 Demystified
Java EE7 Demystified
 
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
 
TY.BSc.IT Java QB U4
TY.BSc.IT Java QB U4TY.BSc.IT Java QB U4
TY.BSc.IT Java QB U4
 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.js
 
Session 37 - JSP - Part 2 (final)
Session 37 - JSP - Part 2 (final)Session 37 - JSP - Part 2 (final)
Session 37 - JSP - Part 2 (final)
 

Recently uploaded

JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingScyllaDB
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهMohamed Sweelam
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistandanishmna97
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxMasterG
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 

Recently uploaded (20)

JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 

JSP.pptx

  • 1. U18CSI6201 INTERNET & WEB PROGRAMMING JSP V.SENTHIL KUMAR Department of CSE
  • 2. COURSE OUTCOMES CO1: DESIGN A WEBSITE USING HTML (K5, S3) CO2: Apply Cascading Style Sheet to design a HTML Webpage (K3, S2) CO3: Develop a HTML form and validate it using Java Script (K5, S2) CO4: Develop web application using JSP, Servlet (K5, S3) CO5: Develop an XML document and validate it using SCHEMA (K5, S2)
  • 3. AGENDA WHAT & WHY JSP? SERVLET VS JSP JSP ELEMENTS JSP/SERVLETS IN THE ENTERPRISE USING JAVA BEANS IN JSP TAG LIBRARIES AND TAG TYPES
  • 4. What and Why of JSP? • JSP = Java code imbedded in HTML or XML • Static portion of the page is HTML • Dynamic portion is Java • Easy way to develop and maintain dynamic web pages and dynamic XML documents
  • 7. Recommendation • Use JSP • If presentation changes frequently • Presentation is complex • Use Servlets • Validation, simple business logic • Simple/small presentation
  • 8. Anatomy of a JSP Page • Template (static HTML or XML) • JSP Elements • Tag libraries Element Type JSP Syntax Description Directives <%@ directive_name%> Controls to define translation into Java code Scripting <% …………… %> Embed Java code in HTML Actions <jsp: …………. > JSP-specific tag for Java Beans
  • 9.
  • 10.
  • 13. Accessing Servlet Variables • config • request • response • session • out • pageContext • application • page
  • 15. Simplify JSP Development Use Java Beans Use Tag Libraries
  • 16. Model/View/Controller JavaBean Request object JSP/Servlets in the Enterprise Servlet JSP page Data base Web Server Model One Architecture Output doGet/ doPost Input <<forward>> <<creates>> <<uses>>
  • 17. Using Java Beans in JSP Model 1 <HTML> <HEAD><TITLE>JSP Page 2</TITLE></HEAD> <BODY> …. <jsp:useBean id=“employee” class=“javaBeans.Employee” scope=“request” /> .... <br>lastname = <jsp:getProperty name=“employee” property=“lastName” /> <br>firstname = <jsp:getProperty name=“employee” property=“firstName” /> <br>lastname = <%= employee.getLastName() %> <br>firstname = <%= employee.getFirstName() %> …. </BODY> </HTML> Getting values from a java bean Get Java Bean Reference Java Bean class variables
  • 18. Using Java Beans in JSP Model 1 <HTML> <HEAD><TITLE>JSP Page 1</TITLE></HEAD> <BODY> …. <jsp:useBean id=“customer1” class=“control.Customer” scope=“request”> <jsp:setProperty name=“customer1” property=“lastName” value=“Flintstone” /> <jsp:setProperty name=“customer1” property=“firstName” value=“Wilma” /> <% customer1.setUserid(“flintstonew”); %> <% customer1.setPassword(“dino”); %> </jsp:useBean> …. <jsp:forward page=”/jspPage2” />”/> …. </BODY> </HTML> Creating a java bean and setting values in the java bean Create Java Bean Forward request to next JSP page
  • 19. Using Java Beans in JSP Model 1 <HTML> <HEAD><TITLE>JSP Page 2</TITLE></HEAD> <BODY> …. <jsp:useBean id=“customer1” class=“control.Customer” scope=“request” /> .... <br>Last name = <jsp:getProperty name=“customer1” property=“lastName” /> <br>first name = <jsp:getProperty name=“customer1” property=“firstName” /> <br>Username = <% customer1.getUserid(); %> <br>Password = <% customer1.getPassword(); %> …. </BODY> </HTML> Getting values from a java bean Get Java Bean Reference Java Bean class variables
  • 20. Tag Libraries • Create custom XML tags that you can imbed in JSP pages • Custom commands (i.e., macros) • Java tag handler class defined for each custom tag • XML tag in JSP  Java method called for tag
  • 21. Tag Types • XML format • Tag without a body <rkjTagLib:deptHeader/> • Tag without a body but with an attribute <rkjTagLib:table rowcount=5 colcount=3 /> • Tag with body and an attribute <rkjTagLib:table rowcount=5 colcount=3 > Title of Table </rkjTagLIb:table>
  • 22. Tag Handler Class import java.io.*; import java.servlet.jsp.*; import java.servlet.jsp.tagext.*; public class DeptHeader extends TagSupport { public int doStartTag() { try { JspWriter out = pageContext.getOut(); out.println(“<H2>Information Systems Dept.</H1>”); out.println(“<H3>Brigham Young University-Idaho </H3>”); } catch (IOException ioex) { …. } return (SKIP_BODY); } public int doEndTag() { return(EVAL_PAGE); } } Inherit TagSupport Invoked at starting tag Invoked at ending tag
  • 23. Tag Library Descriptor <?xml version=“1.0” encoding=“ISO-8859-1” ?> <!DOCTYPE taglib PUBLIC “-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN” http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd> <taglib> <tlib-version>1.0</tlib-version>> <jspversion>1.2</jspversion> <shortname>homeDirectBank</shortname> <tag> <name>deptHeader</name> <tagclass>homedirectbank.DeptHeader</tagclass> <bodycontent>EMPTY</bodycontent> <info>Inserts IS department header</info> </tag> </taglib>
  • 24. Using Tag in JSP Page <taglib> <tlibversion>1.1</tlibversion> <jspversion>1.2</jspversion> <shortname>homeDirectBank</shortname> <tag> <name>deptHeader</name> <tagclass>com.taglib.homedirectbank.DeptHeader</tagclass> <bodycontent>EMPTY</bodycontent> <info>Inserts IS department header</info> </tag> </taglib> Tag Library Descriptor (homeDrectBank) <%@ taglib uri=“/homeDirectBank” prefix=“utils”> <HTML> <HEAD><TITLE>Test Servlet</TITLE></HEAD> <BODY> <utils:deptHeader /> ….. ….. </BODY> </HTML> } JSP Page import java.io.*; import java.servlet.jsp.*; import java.servlet.jsp.tagext.*; public class DepHeader extends TagSupport { public int doStartTag() { try { JspWriter out = pageContext.getOut(); out.println(“<H2>Information Systems Dept.</H1>”); out.println(“<H3>Brigham Young University-Idaho </H3>”); } catch (IOException ioex) { …. } return (SKIP_BODY); } public int doEndTag() { return(EVAL_PAGE); } } Tag Handler Class maps uses