SlideShare a Scribd company logo
1 of 28
Java & JEE Training
Session 37 – JSP Part 2 (Final)
Page 1Classification: Restricted
Agenda
• JSP vs Servlet
• LifeCycle of Servlet
• JSP Elements
• JSP Page directive
• Directives vs Action tags
Page 2Classification: Restricted
Review of last session on JSP
• JSP vs Servlet
• Model1 vs Model 2 (MVC) architecture
• JSP Elements
• Declaration
• Expression
• Scriplets
Page 3Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 3
JSP vs Servlet
Servlet = HTML in a Java class
JSP = Java in an HTML page
out.println(“<h1> Hello World! </h1>”);
<%= request.getParameter("title") %>
Page 4Classification: Restricted
Model 1 Architecture
Page 5Classification: Restricted
Model 2 Architecture
Page 6Classification: Restricted
LifeCycle of Servlet
Page 7Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 7
JSP Elements
• Declarations <%! code %>
• Expressions <%= expression %>
• Scriptlets <% code %>
JSP Part 2
Directives -
page, include, taglib
Page 10Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 10
JSP Page Directive
• Directives are messages to the JSP container and do not produce output
into the current output stream
• Syntax:
<%@ directive attribute=“value” %>
<%@ directive attribute1=“value1”
attribute1 =“value2” … %>
There are three types of directives:
1. page
2. include
3. taglib
XML form:
<jsp:directive.directiveType attribute=“value” />
Page 11Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 11
Page Directive
• Defines attributes that apply to an entire JSP page.
<%@ page
[ language="java" ]
[ extends="package.class" ]
[ import="{package.class | package.*}, ..." ]
[ session="true|false" ]
[ buffer="none|8kb|sizekb" ]
[ autoFlush="true|false" ]
[ isThreadSafe="true|false" ]
[ info="text" ]
[ errorPage="relativeURL" ]
[ contentType="mimeType [ ;charset=characterSet ]" [
isErrorPage="true|false" ]
%>
Page 12Classification: Restricted
Page directive example..
<%@ page import="java.util.*" %>
<HTML>
<BODY>
<%
System.out.println( "Evaluating date now" );
Date date = new Date();
%>
Hello! The time is now <%= date %>
</BODY>
</HTML>
Page 13Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 13
Include Directive
• Includes a static file in a JSP file, parsing the file's JSP elements.
• Syntax
<%@ include file="relativeURL" %>
The <%@ include %> directive inserts a file of text or code in a JSP file at
translation time, when the JSP file is compiled.
<%@ include %> process is static. A static include means that the text
of the included file is added to the JSP file.
You may include a JSP or HTML file like this. E.g. for headers and
footers.
Page 14Classification: Restricted
Include directive example…
• index.jsp
<html>
<head>
<title>Main JSP Page</title>
</head>
<body>
<%@ include file="file1.jsp" %>
Main JSP Page: Content between two include directives.
<%@ include file="file2.jsp" %>
</body>
</html>
• file1.jsp
<p align="center">
This is my File1.jsp and I will include it in index.jsp using include directive
</p>
• file2.jsp
<p align="center">
This is File2.jsp
</p>
Page 15Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 15
Taglib Directive
• Defines a tag library and prefix for the custom tags used in the JSP page.
<%@ taglib uri="URIToTagLibrary" prefix="tagPrefix" %>
<%@ taglib uri="http://thathost/tags" prefix="public" %>
<public:loop>
</public:loop>
The <%@ taglib %> directive declares that the JSP file uses custom tags,
names the tag library that defines them, and specifies their tag prefix.
We will look into this further when we look at frameworks like Struts
and Spring.
JSP Action Tags:
include, forward, useBean
Page 17Classification: Restricted
Directives vs Action tags
• Directives are used during translation phase while actions are used during
request processing phase.
• Unlike Directives, Actions are re-evaluated each time the page is accessed.
Page 18Classification: Restricted
<jsp:include>
<html>
<head>
<title>Demo of JSP include Action Tag</title>
</head>
<body>
<h3>JSP page: Demo Include</h3>
<jsp:include page="sample.jsp" />
</body>
</html>
Page 19Classification: Restricted
<jsp:include> with parameters
index.jsp
<html>
<head>
<title>JSP Include example with parameters</title>
</head>
<body>
<h2>This is index.jsp Page</h2>
<jsp:include page="display.jsp">
<jsp:param name="userid" value=“Pawan" />
<jsp:param name="password" value=“Pawan" />
<jsp:param name="name" value=“Pawan Kumar" />
<jsp:param name="age" value="27" />
</jsp:include>
</body>
</html>
display.jsp
<html>
<head>
<title>Display Page</title>
</head>
<body>
<h2>Hello this is a display.jsp Page</h2>
UserID: <%=request.getParameter("userid") %><br>
Password is: <%=request.getParameter("password")
%><br>
User Name: <%=request.getParameter("name")
%><br>
Age: <%=request.getParameter("age") %>
</body>
</html>
Page 20Classification: Restricted
<jsp:forward> without parameters
• first.jsp
<html>
<head>
<title>Demo of JSP Forward Action Tag</title>
</head>
<body>
<h3>JSP page: Demo forward</h3>
<jsp:forward page="second.jsp" />
</body>
</html>
Page 21Classification: Restricted
<jsp:forward> with parameters
index.jsp
<html>
<head>
<title>JSP Include example with parameters</title>
</head>
<body>
<h2>This is index.jsp Page</h2>
<jsp:forward page="display.jsp">
<jsp:param name="userid" value=“Pawan" />
<jsp:param name="password" value=“Pawan" />
<jsp:param name="name" value=“Pawan Kumar" />
<jsp:param name="age" value="27" />
</jsp:forward>
</body>
</html>
display.jsp
<html>
<head>
<title>Display Page</title>
</head>
<body>
<h2>Hello this is a display.jsp Page</h2>
UserID: <%=request.getParameter("userid") %><br>
Password is: <%=request.getParameter("password")
%><br>
User Name: <%=request.getParameter("name")
%><br>
Age: <%=request.getParameter("age") %>
</body>
</html>
Page 22Classification: Restricted
<jsp:useBean> : Bean class
• First write a bean Details.java with username, age, password as properties.
public class Details {
public Details() {
}
private String username;
private int age;
private String password;
// Write getter and setter methods here…
}
Page 23Classification: Restricted
<jsp:useBean> : index.jsp
<html>
<head><title>
useBean, getProperty and setProperty example
</title></head>
<form action="userdetails.jsp" method="post">
User Name: <input type="text" name="username"><br>
User Password: <input type="password" name="password"><br>
User Age: <input type="text" name="age"><br>
<input type="submit" value="register">
</form>
</html>
Page 24Classification: Restricted
<jsp:useBean>: userDetails.jsp
<jsp:useBean id="userinfo“ class=“mypackage.Details">
</jsp:useBean>
<jsp:setProperty property="*" name="userinfo"/>
You have enterted below details:<br>
<jsp:getProperty property="username" name="userinfo"/><br>
<jsp:getProperty property="password" name="userinfo"/><br>
<jsp:getProperty property="age" name="userinfo" /><br>
Page 25Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 25
Conclusion
JavaServer Pages (JSP) lets you separate the dynamic part of your pages
from the static HTML.
1. One can simply write the regular HTML in the normal manner, using
whatever Web-page-building tools you normally use.
2. One can enclose then the code for the dynamic parts in special tags,
most of which
start with "<%"
and end with "%>"
Page 26Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 26
Topics to be covered in next session
• Core Java features with Examples
• Assertions
• Varargs
• Static import
• Autoboxing and Unboxing
• Enum
• Covariant
• Annotations
• Generics
• Instrumentation
• Catch Multiple Exceptions
Page 27Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 27
Thank you!

More Related Content

What's hot

Session 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsPawanMM
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2PawanMM
 
Session 29 - Servlets - Part 5
Session 29 - Servlets - Part 5Session 29 - Servlets - Part 5
Session 29 - Servlets - Part 5PawanMM
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2PawanMM
 
JSP - Part 2 (Final)
JSP - Part 2 (Final) JSP - Part 2 (Final)
JSP - Part 2 (Final) Hitesh-Java
 
Session 28 - Servlets - Part 4
Session 28 - Servlets - Part 4Session 28 - Servlets - Part 4
Session 28 - Servlets - Part 4PawanMM
 
Hibernate - Part 2
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2 Hitesh-Java
 
Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCHitesh-Java
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction Hitesh-Java
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & AjaxAng Chen
 
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 BasicIMC Institute
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization Hitesh-Java
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: ServletsFahad Golra
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansPawanMM
 
WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0Jeffrey West
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedIMC Institute
 

What's hot (19)

Session 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, Servlets
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
 
Session 29 - Servlets - Part 5
Session 29 - Servlets - Part 5Session 29 - Servlets - Part 5
Session 29 - Servlets - Part 5
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
 
JSP - Part 2 (Final)
JSP - Part 2 (Final) JSP - Part 2 (Final)
JSP - Part 2 (Final)
 
Session 28 - Servlets - Part 4
Session 28 - Servlets - Part 4Session 28 - Servlets - Part 4
Session 28 - Servlets - Part 4
 
JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
 
Hibernate - Part 2
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2
 
Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVC
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & Ajax
 
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
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI Beans
 
WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
Java part 3
Java part  3Java part  3
Java part 3
 

Similar to Session 37 - JSP - Part 2 (final)

Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...WebStackAcademy
 
Java serverpages
Java serverpagesJava serverpages
Java serverpagesAmit Kumar
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
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 Ayes Chinmay
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESYoga Raja
 
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
Session 5 : intro to jsp  - Giáo trình Bách Khoa AptechSession 5 : intro to jsp  - Giáo trình Bách Khoa Aptech
Session 5 : intro to jsp - Giáo trình Bách Khoa AptechMasterCode.vn
 

Similar to Session 37 - JSP - Part 2 (final) (20)

Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
 
Jsp
JspJsp
Jsp
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Java serverpages
Java serverpagesJava serverpages
Java serverpages
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
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
JspJsp
Jsp
 
Java .ppt
Java .pptJava .ppt
Java .ppt
 
25.ppt
25.ppt25.ppt
25.ppt
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Jsp1
Jsp1Jsp1
Jsp1
 
Introduction to jsp
Introduction to jspIntroduction to jsp
Introduction to jsp
 
Introduction to jsp
Introduction to jspIntroduction to jsp
Introduction to jsp
 
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
Session 5 : intro to jsp  - Giáo trình Bách Khoa AptechSession 5 : intro to jsp  - Giáo trình Bách Khoa Aptech
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 
JSP Part 2
JSP Part 2JSP Part 2
JSP Part 2
 
4. jsp
4. jsp4. jsp
4. jsp
 
Jsp
JspJsp
Jsp
 
10 jsp-scripting-elements
10 jsp-scripting-elements10 jsp-scripting-elements
10 jsp-scripting-elements
 

More from PawanMM

Session 48 - JS, JSON and AJAX
Session 48 - JS, JSON and AJAXSession 48 - JS, JSON and AJAX
Session 48 - JS, JSON and AJAXPawanMM
 
Session 46 - Spring - Part 4 - Spring MVC
Session 46 - Spring - Part 4 - Spring MVCSession 46 - Spring - Part 4 - Spring MVC
Session 46 - Spring - Part 4 - Spring MVCPawanMM
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPPawanMM
 
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based ConfigurationSession 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based ConfigurationPawanMM
 
Session 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate IntegrationSession 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate IntegrationPawanMM
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionPawanMM
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1PawanMM
 
Session 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise JavaSession 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise JavaPawanMM
 
Session 23 - JDBC
Session 23 - JDBCSession 23 - JDBC
Session 23 - JDBCPawanMM
 
Session 22 - Java IO, Serialization
Session 22 - Java IO, SerializationSession 22 - Java IO, Serialization
Session 22 - Java IO, SerializationPawanMM
 
Session 21 - Inner Classes
Session 21 - Inner ClassesSession 21 - Inner Classes
Session 21 - Inner ClassesPawanMM
 
Session 20 - Collections - Maps
Session 20 - Collections - MapsSession 20 - Collections - Maps
Session 20 - Collections - MapsPawanMM
 
Session 19 - Review Session
Session 19 - Review SessionSession 19 - Review Session
Session 19 - Review SessionPawanMM
 
Session 18 - Review Session and Attending Java Interviews
Session 18 - Review Session and Attending Java InterviewsSession 18 - Review Session and Attending Java Interviews
Session 18 - Review Session and Attending Java InterviewsPawanMM
 
Session 17 - Collections - Lists, Sets
Session 17 - Collections - Lists, SetsSession 17 - Collections - Lists, Sets
Session 17 - Collections - Lists, SetsPawanMM
 
Session 16 - Collections - Sorting, Comparing Basics
Session 16 - Collections - Sorting, Comparing BasicsSession 16 - Collections - Sorting, Comparing Basics
Session 16 - Collections - Sorting, Comparing BasicsPawanMM
 

More from PawanMM (16)

Session 48 - JS, JSON and AJAX
Session 48 - JS, JSON and AJAXSession 48 - JS, JSON and AJAX
Session 48 - JS, JSON and AJAX
 
Session 46 - Spring - Part 4 - Spring MVC
Session 46 - Spring - Part 4 - Spring MVCSession 46 - Spring - Part 4 - Spring MVC
Session 46 - Spring - Part 4 - Spring MVC
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based ConfigurationSession 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
 
Session 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate IntegrationSession 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate Integration
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1
 
Session 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise JavaSession 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise Java
 
Session 23 - JDBC
Session 23 - JDBCSession 23 - JDBC
Session 23 - JDBC
 
Session 22 - Java IO, Serialization
Session 22 - Java IO, SerializationSession 22 - Java IO, Serialization
Session 22 - Java IO, Serialization
 
Session 21 - Inner Classes
Session 21 - Inner ClassesSession 21 - Inner Classes
Session 21 - Inner Classes
 
Session 20 - Collections - Maps
Session 20 - Collections - MapsSession 20 - Collections - Maps
Session 20 - Collections - Maps
 
Session 19 - Review Session
Session 19 - Review SessionSession 19 - Review Session
Session 19 - Review Session
 
Session 18 - Review Session and Attending Java Interviews
Session 18 - Review Session and Attending Java InterviewsSession 18 - Review Session and Attending Java Interviews
Session 18 - Review Session and Attending Java Interviews
 
Session 17 - Collections - Lists, Sets
Session 17 - Collections - Lists, SetsSession 17 - Collections - Lists, Sets
Session 17 - Collections - Lists, Sets
 
Session 16 - Collections - Sorting, Comparing Basics
Session 16 - Collections - Sorting, Comparing BasicsSession 16 - Collections - Sorting, Comparing Basics
Session 16 - Collections - Sorting, Comparing Basics
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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 WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 

Session 37 - JSP - Part 2 (final)

  • 1. Java & JEE Training Session 37 – JSP Part 2 (Final)
  • 2. Page 1Classification: Restricted Agenda • JSP vs Servlet • LifeCycle of Servlet • JSP Elements • JSP Page directive • Directives vs Action tags
  • 3. Page 2Classification: Restricted Review of last session on JSP • JSP vs Servlet • Model1 vs Model 2 (MVC) architecture • JSP Elements • Declaration • Expression • Scriplets
  • 4. Page 3Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 3 JSP vs Servlet Servlet = HTML in a Java class JSP = Java in an HTML page out.println(“<h1> Hello World! </h1>”); <%= request.getParameter("title") %>
  • 8. Page 7Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 7 JSP Elements • Declarations <%! code %> • Expressions <%= expression %> • Scriptlets <% code %>
  • 11. Page 10Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 10 JSP Page Directive • Directives are messages to the JSP container and do not produce output into the current output stream • Syntax: <%@ directive attribute=“value” %> <%@ directive attribute1=“value1” attribute1 =“value2” … %> There are three types of directives: 1. page 2. include 3. taglib XML form: <jsp:directive.directiveType attribute=“value” />
  • 12. Page 11Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 11 Page Directive • Defines attributes that apply to an entire JSP page. <%@ page [ language="java" ] [ extends="package.class" ] [ import="{package.class | package.*}, ..." ] [ session="true|false" ] [ buffer="none|8kb|sizekb" ] [ autoFlush="true|false" ] [ isThreadSafe="true|false" ] [ info="text" ] [ errorPage="relativeURL" ] [ contentType="mimeType [ ;charset=characterSet ]" [ isErrorPage="true|false" ] %>
  • 13. Page 12Classification: Restricted Page directive example.. <%@ page import="java.util.*" %> <HTML> <BODY> <% System.out.println( "Evaluating date now" ); Date date = new Date(); %> Hello! The time is now <%= date %> </BODY> </HTML>
  • 14. Page 13Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 13 Include Directive • Includes a static file in a JSP file, parsing the file's JSP elements. • Syntax <%@ include file="relativeURL" %> The <%@ include %> directive inserts a file of text or code in a JSP file at translation time, when the JSP file is compiled. <%@ include %> process is static. A static include means that the text of the included file is added to the JSP file. You may include a JSP or HTML file like this. E.g. for headers and footers.
  • 15. Page 14Classification: Restricted Include directive example… • index.jsp <html> <head> <title>Main JSP Page</title> </head> <body> <%@ include file="file1.jsp" %> Main JSP Page: Content between two include directives. <%@ include file="file2.jsp" %> </body> </html> • file1.jsp <p align="center"> This is my File1.jsp and I will include it in index.jsp using include directive </p> • file2.jsp <p align="center"> This is File2.jsp </p>
  • 16. Page 15Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 15 Taglib Directive • Defines a tag library and prefix for the custom tags used in the JSP page. <%@ taglib uri="URIToTagLibrary" prefix="tagPrefix" %> <%@ taglib uri="http://thathost/tags" prefix="public" %> <public:loop> </public:loop> The <%@ taglib %> directive declares that the JSP file uses custom tags, names the tag library that defines them, and specifies their tag prefix. We will look into this further when we look at frameworks like Struts and Spring.
  • 17. JSP Action Tags: include, forward, useBean
  • 18. Page 17Classification: Restricted Directives vs Action tags • Directives are used during translation phase while actions are used during request processing phase. • Unlike Directives, Actions are re-evaluated each time the page is accessed.
  • 19. Page 18Classification: Restricted <jsp:include> <html> <head> <title>Demo of JSP include Action Tag</title> </head> <body> <h3>JSP page: Demo Include</h3> <jsp:include page="sample.jsp" /> </body> </html>
  • 20. Page 19Classification: Restricted <jsp:include> with parameters index.jsp <html> <head> <title>JSP Include example with parameters</title> </head> <body> <h2>This is index.jsp Page</h2> <jsp:include page="display.jsp"> <jsp:param name="userid" value=“Pawan" /> <jsp:param name="password" value=“Pawan" /> <jsp:param name="name" value=“Pawan Kumar" /> <jsp:param name="age" value="27" /> </jsp:include> </body> </html> display.jsp <html> <head> <title>Display Page</title> </head> <body> <h2>Hello this is a display.jsp Page</h2> UserID: <%=request.getParameter("userid") %><br> Password is: <%=request.getParameter("password") %><br> User Name: <%=request.getParameter("name") %><br> Age: <%=request.getParameter("age") %> </body> </html>
  • 21. Page 20Classification: Restricted <jsp:forward> without parameters • first.jsp <html> <head> <title>Demo of JSP Forward Action Tag</title> </head> <body> <h3>JSP page: Demo forward</h3> <jsp:forward page="second.jsp" /> </body> </html>
  • 22. Page 21Classification: Restricted <jsp:forward> with parameters index.jsp <html> <head> <title>JSP Include example with parameters</title> </head> <body> <h2>This is index.jsp Page</h2> <jsp:forward page="display.jsp"> <jsp:param name="userid" value=“Pawan" /> <jsp:param name="password" value=“Pawan" /> <jsp:param name="name" value=“Pawan Kumar" /> <jsp:param name="age" value="27" /> </jsp:forward> </body> </html> display.jsp <html> <head> <title>Display Page</title> </head> <body> <h2>Hello this is a display.jsp Page</h2> UserID: <%=request.getParameter("userid") %><br> Password is: <%=request.getParameter("password") %><br> User Name: <%=request.getParameter("name") %><br> Age: <%=request.getParameter("age") %> </body> </html>
  • 23. Page 22Classification: Restricted <jsp:useBean> : Bean class • First write a bean Details.java with username, age, password as properties. public class Details { public Details() { } private String username; private int age; private String password; // Write getter and setter methods here… }
  • 24. Page 23Classification: Restricted <jsp:useBean> : index.jsp <html> <head><title> useBean, getProperty and setProperty example </title></head> <form action="userdetails.jsp" method="post"> User Name: <input type="text" name="username"><br> User Password: <input type="password" name="password"><br> User Age: <input type="text" name="age"><br> <input type="submit" value="register"> </form> </html>
  • 25. Page 24Classification: Restricted <jsp:useBean>: userDetails.jsp <jsp:useBean id="userinfo“ class=“mypackage.Details"> </jsp:useBean> <jsp:setProperty property="*" name="userinfo"/> You have enterted below details:<br> <jsp:getProperty property="username" name="userinfo"/><br> <jsp:getProperty property="password" name="userinfo"/><br> <jsp:getProperty property="age" name="userinfo" /><br>
  • 26. Page 25Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 25 Conclusion JavaServer Pages (JSP) lets you separate the dynamic part of your pages from the static HTML. 1. One can simply write the regular HTML in the normal manner, using whatever Web-page-building tools you normally use. 2. One can enclose then the code for the dynamic parts in special tags, most of which start with "<%" and end with "%>"
  • 27. Page 26Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 26 Topics to be covered in next session • Core Java features with Examples • Assertions • Varargs • Static import • Autoboxing and Unboxing • Enum • Covariant • Annotations • Generics • Instrumentation • Catch Multiple Exceptions
  • 28. Page 27Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 27 Thank you!