SlideShare a Scribd company logo
1 of 28
Java JSP Training
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 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design PatternsSession 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design PatternsPawanMM
 
Session 36 - JSP - Part 1
Session 36 - JSP - Part 1Session 36 - JSP - Part 1
Session 36 - JSP - Part 1PawanMM
 
Session 35 - Design Patterns
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design PatternsPawanMM
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOPHitesh-Java
 
Session 32 - Session Management using Cookies
Session 32 - Session Management using CookiesSession 32 - Session Management using Cookies
Session 32 - Session Management using CookiesPawanMM
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsPawanMM
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization Hitesh-Java
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Struts 2 - Hibernate Integration
Struts 2 - Hibernate Integration Struts 2 - Hibernate Integration
Struts 2 - Hibernate Integration Hitesh-Java
 
Session 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsPawanMM
 
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
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1Hitesh-Java
 
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
 
Session 33 - Session Management using other Techniques
Session 33 - Session Management using other TechniquesSession 33 - Session Management using other Techniques
Session 33 - Session Management using other TechniquesPawanMM
 
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
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: ServletsFahad Golra
 
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
 
Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6PawanMM
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCIMC Institute
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, mavenFahad Golra
 

What's hot (20)

Session 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design PatternsSession 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design Patterns
 
Session 36 - JSP - Part 1
Session 36 - JSP - Part 1Session 36 - JSP - Part 1
Session 36 - JSP - Part 1
 
Session 35 - Design Patterns
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design Patterns
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Session 32 - Session Management using Cookies
Session 32 - Session Management using CookiesSession 32 - Session Management using Cookies
Session 32 - Session Management using Cookies
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Struts 2 - Hibernate Integration
Struts 2 - Hibernate Integration Struts 2 - Hibernate Integration
Struts 2 - Hibernate Integration
 
Session 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, 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
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1
 
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
 
Session 33 - Session Management using other Techniques
Session 33 - Session Management using other TechniquesSession 33 - Session Management using other Techniques
Session 33 - Session Management using other Techniques
 
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
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
 
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
 
Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVC
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
 

Similar to 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
 
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 Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
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 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
JspJsp
Jsp
 
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 - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
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
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 
4. jsp
4. jsp4. jsp
4. jsp
 
JSP Part 2
JSP Part 2JSP Part 2
JSP Part 2
 
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
 
Jsp
JspJsp
Jsp
 
10 jsp-scripting-elements
10 jsp-scripting-elements10 jsp-scripting-elements
10 jsp-scripting-elements
 

More from Hitesh-Java

Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesHitesh-Java
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps Hitesh-Java
 
Review Session - Part -2
Review Session - Part -2Review Session - Part -2
Review Session - Part -2Hitesh-Java
 
Review Session and Attending Java Interviews
Review Session and Attending Java Interviews Review Session and Attending Java Interviews
Review Session and Attending Java Interviews Hitesh-Java
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets Hitesh-Java
 
Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Hitesh-Java
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List Hitesh-Java
 
Exception Handling - Continued
Exception Handling - Continued Exception Handling - Continued
Exception Handling - Continued Hitesh-Java
 
Exception Handling - Part 1
Exception Handling - Part 1 Exception Handling - Part 1
Exception Handling - Part 1 Hitesh-Java
 
OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers Hitesh-Java
 
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesOOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesHitesh-Java
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3Hitesh-Java
 
OOP with Java - Continued
OOP with Java - Continued OOP with Java - Continued
OOP with Java - Continued Hitesh-Java
 
Intro to Object Oriented Programming with Java
Intro to Object Oriented Programming with Java Intro to Object Oriented Programming with Java
Intro to Object Oriented Programming with Java Hitesh-Java
 
Practice Session
Practice Session Practice Session
Practice Session Hitesh-Java
 

More from Hitesh-Java (20)

Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
 
JDBC
JDBCJDBC
JDBC
 
Inner Classes
Inner Classes Inner Classes
Inner Classes
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
 
Review Session - Part -2
Review Session - Part -2Review Session - Part -2
Review Session - Part -2
 
Review Session and Attending Java Interviews
Review Session and Attending Java Interviews Review Session and Attending Java Interviews
Review Session and Attending Java Interviews
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
 
Object Class
Object Class Object Class
Object Class
 
Exception Handling - Continued
Exception Handling - Continued Exception Handling - Continued
Exception Handling - Continued
 
Exception Handling - Part 1
Exception Handling - Part 1 Exception Handling - Part 1
Exception Handling - Part 1
 
OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers
 
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesOOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and Interfaces
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3
 
OOP with Java - Continued
OOP with Java - Continued OOP with Java - Continued
OOP with Java - Continued
 
Intro to Object Oriented Programming with Java
Intro to Object Oriented Programming with Java Intro to Object Oriented Programming with Java
Intro to Object Oriented Programming with Java
 
Practice Session
Practice Session Practice Session
Practice Session
 

Recently uploaded

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
 
#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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

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
 
#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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

JSP - Part 2 (Final)

  • 1. Java JSP Training 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!