SlideShare a Scribd company logo
Java JSP Training
JSP Part 1
Page 1Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 1
Agenda
• JSP (Java Server Pages Technology)
• JSP vs Servlet
• MVC Architecture
• Scriplet
Page 2Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 2
JavaServer Pages Technology
• JavaServer Pages (JSP) technology provides a simplified, fast way to create
web pages that display dynamically-generated content.
• Server Page technology = the web pages are dynamically built on the server
side. E.g. JSP, ASP, BSP
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") %>
MVC Architecture
Page 5Classification: Restricted
Model 1 Architecture
Page 6Classification: Restricted
Model 2 Architecture
(also known as MVC or Model-View-Controller)
Single Responsibility Principle,
Separation of Concerns.
Page 7Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 7
JSP Page
• A JSP page is a page created by the web developer that includes JSP
technology-specific tags, declarations, and possibly scriptlets, in
combination with other static HTML or XML tags.
• A JSP page has the extension .jsp; this signals to the web server that the JSP
engine will process elements on this page.
• Pages built using JSP technology are typically implemented using a
translation phase that is performed once, the first time the page is called.
The page is compiled into a Java Servlet class and remains in server
memory, so subsequent calls to the page have very fast response times.
Page 8Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 8
Overview
• JavaServer Pages (JSP) lets you separate the dynamic part of your pages
from the static HTML.
HTML tags and text
<% some JSP code here %>
HTML tags and text
<I>
<%= request.getParameter("title") %>
</I>
You normally give your file a .jsp extension, and typically install it in any
place you could place a normal Web page
Page 9Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 9
Client and Server with JSP
Page 10Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 10
Translation Time
• A JSP application is usually a collection of JSP files, HTML files, graphics
and other resources.
• A JSP page is compiled when your user loads it into a Web browser
1. When the user loads the page for the first time, the files that make up the
application are all translated together, without any dynamic data, into
one Java source file (a .java file)
2. The .java file is compiled to a .class file. In most implementations, the
.java file is a Java servlet that complies with the Java Servlet API.
Page 11Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 11
Simple JSP Page
<%@ page info=“A Simple JSP Sample” %>
<HTML>
<H1> First JSP Page </H1>
<BODY>
<% out.println(“Welcome to JSP world”); %>
</BODY>
</HTML>
Page 12Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 12
How JSP Works?
User Request – JSP File Requested
Server
File
ChangedCreate Source from JSP
Compile Execute Servlet
Page 13Classification: Restricted
Review of Life Cycle of Servlet
Page 14Classification: Restricted
JSP Lifecycle
1.Translation (JSP
 Servlet)
2.Compilation
(Servlet
compiled)
3.Loading
4.Instantiation
5.Initialization
6.Request
Processing
7.Destruction
Page 15Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 15
JSP Elements
• Declarations <%! code %>
• Expressions <%= expression %>
• Scriptlets <% code %>
Page 16Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 16
HTML Comment
• Generates a comment that is sent to the client.
• Syntax
<!-- comment [ <%= expression %> ] -->
• Example:
<!-- This page was loaded on
<%= (new java.util.Date()).toLocaleString() %>
-->
Page 17Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 17
Declaration
• Declares a variable or method valid in the scripting language used in the JSP page.
• Syntax
<%! declaration; [ declaration; ]+ ... %>
• Examples
<%! String destin; %>
<%! public String getDestination()
{return destin;}%>
<%! Circle a = new Circle(2.0); %>
• You can declare any number of variables or methods within one declaration
element, as long as you end each declaration with a semicolon.
• The declaration must be valid in the Java programming language.
Page 18Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 18
Declaration Example: Variables declaration
<HTML>
<HEAD><TITLE>JSP Declarations</TITLE></HEAD>
<BODY><H1>JSP Declarations</H1>
<%! private int keepCount = 0; %>
<H2>
Page accessed:
<%= ++keepCount %>
times
</H2>
</BODY>
</HTML>
Best Practice: Never use instance
variables in Servlets. (Multithreading)
Page 19Classification: Restricted
Declaration example: Methods declaration
<html>
<head>
<title>Methods Declaration</title>
</head>
<body>
<%!
int sum(int num1, int num2, int num3){
return num1+num2+num3;
}
%>
<%= "Result is: " + sum(10,40,50) %>
</body>
</html>
Page 20Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 20
Predefined Variable – Implicit Objects
• request – Object of HttpServletRequest (request parameters, HTTP headers, cookies
• response – Object of HttpServletResponse
• out - Object of PrintWriter buffered version JspWriter
• session - Object of HttpSession associated with the request
• application - Object of ServletContext shared by all servlets in the engine
• config - Object of ServletConfig
• pageContext - Object of PageContext in JSP for a single point of access
e.g. pageContext.getSession()
• page – variable synonym for this object
e.g. <%= ((Servlet)page).getServletInfo () %>
Page 21Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 21
Expression
• Contains an expression valid in the scripting language used in the JSP page. Syntax:
<%= expression %>
<%! String name = new String(“JSP World”); %>
<%! public String getName() { return name; } %>
<B><%= getName() %></B>
• Description:
An expression element contains a scripting language expression that is
evaluated, converted to a String, and inserted where the expression appears in
the JSP file.
• Because the value of an expression is converted to a String, you can use an
expression within a line of text, whether or not it is tagged with HTML, in a
JSPfile. Expressions are evaluated from left to right.
Page 22Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 22
Expression Example
<HTML>
<HEAD>
<TITLE>JSP Expressions</TITLE>
</HEAD>
<BODY>
<H2>JSP Expressions</H2>
<UL>
<LI>Current time: <%= new java.util.Date() %>
<LI>Your hostname: <%= request.getRemoteHost()%>
<LI>Your session ID: <%= session.getId() %>
</UL>
</BODY>
</HTML>
Page 23Classification: Restricted
Expression Example 2
<html>
<head>
<title>JSP expression tag example1</title>
</head>
<body>
<%= 2+4*5 %>
</body>
</html>
Page 24Classification: Restricted
Expression Example 3
<html>
<head>
<title>JSP expression tag example2</title>
</head>
<body>
<%
int a=10;
int b=20;
int c=30;
%>
<%= a+b+c %>
</body>
</html>
Page 25Classification: Restricted
Expression Example 4
index.jsp
<html>
<head>
<title> JSP expression tag example3 </title>
</head>
<body>
<% application.setAttribute("MyName", "Chaitanya"); %>
<a href="display.jsp">Click here for display</a>
</body>
</html>
display.jsp
<html>
<head>
<title>Display Page</title>
</head>
<body>
<%="This is a String" %><br>
<%= application.getAttribute("MyName") %>
</body>
</html>
Page 26Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 26
Scriptlet
• Contains a code fragment valid in the page scripting language.
• Syntax
<% code fragment %>
<%
String var1 = request.getParameter("name");
out.println(var1);
%>
• This code will be placed in the generated servlet method:
_jspService()
Page 27Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 27
Scriplet Example
<HTML>
<HEAD><TITLE>Weather</TITLE></HEAD>
<BODY>
<H2>Today's weather</H2>
<% if (Math.random() < 0.5) { %>
Today will be a <B>sunny</B> day!
<% } else { %>
Today will be a <B>windy</B> day!
<% } %>
</BODY>
</HTML>
Page 28Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 28
Topics to be covered in next session
• JSP vs Servlet
• LifeCycle of Servlet
• JSP Elements
• JSP Page directive
• Directives vs Action tags
Page 29Classification: Restricted
Copyright @ 2000 Jordan Anastasiade. All rights reserved. 29
Thank you!

More Related Content

What's hot

Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview QuestionsSyed Shahul
 
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
PawanMM
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
Hitesh-Java
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questions
Arun Vasanth
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
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
PawanMM
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
Muthuselvam RS
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
Pankaj Singh
 
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
Hitesh-Java
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
Hitesh-Java
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Manav Prasad
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
kamal kotecha
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
Mumbai Academisc
 

What's hot (18)

Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
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
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questions
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
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 Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
 
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
 
Hibernate3 q&a
Hibernate3 q&aHibernate3 q&a
Hibernate3 q&a
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 

Similar to JSP - Part 1

Session 36 - JSP - Part 1
Session 36 - JSP - Part 1Session 36 - JSP - Part 1
Session 36 - JSP - Part 1
PawanMM
 
Java serverpages
Java serverpagesJava serverpages
Java serverpages
Amit Kumar
 
10 jsp-scripting-elements
10 jsp-scripting-elements10 jsp-scripting-elements
10 jsp-scripting-elements
Phạm Thu Thủy
 
Jsp
JspJsp
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 sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
Sasidhar Kothuru
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
NishaRohit6
 
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
 
Java .ppt
Java .pptJava .ppt
Java .ppt
MuhammedYaseenMc
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Shah Nawaz Bhurt
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
Yoga Raja
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
vishal choudhary
 
Jsp
JspJsp
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
Vipin Yadav
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
ManishaPatil932723
 
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
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
ShahDhruv21
 

Similar to JSP - Part 1 (20)

Session 36 - JSP - Part 1
Session 36 - JSP - Part 1Session 36 - JSP - Part 1
Session 36 - JSP - Part 1
 
Java serverpages
Java serverpagesJava serverpages
Java serverpages
 
10 jsp-scripting-elements
10 jsp-scripting-elements10 jsp-scripting-elements
10 jsp-scripting-elements
 
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 sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Session 37 - JSP - Part 2 (final)
Session 37 - JSP - Part 2 (final)Session 37 - JSP - Part 2 (final)
Session 37 - JSP - Part 2 (final)
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
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 PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Jsp
JspJsp
Jsp
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
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 Directives
JSP DirectivesJSP Directives
JSP Directives
 

More from Hitesh-Java

Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVC
Hitesh-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
 
JDBC
JDBCJDBC
Inner Classes
Inner Classes Inner Classes
Inner Classes
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 -2
Hitesh-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
 
Object Class
Object Class Object Class
Object Class
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 Interfaces
Hitesh-Java
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3
Hitesh-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
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
Hitesh-Java
 

More from Hitesh-Java (20)

Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVC
 
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
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
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
 

Recently uploaded

Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 

Recently uploaded (20)

Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 

JSP - Part 1

  • 2. Page 1Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 1 Agenda • JSP (Java Server Pages Technology) • JSP vs Servlet • MVC Architecture • Scriplet
  • 3. Page 2Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 2 JavaServer Pages Technology • JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content. • Server Page technology = the web pages are dynamically built on the server side. E.g. JSP, ASP, BSP
  • 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") %>
  • 7. Page 6Classification: Restricted Model 2 Architecture (also known as MVC or Model-View-Controller) Single Responsibility Principle, Separation of Concerns.
  • 8. Page 7Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 7 JSP Page • A JSP page is a page created by the web developer that includes JSP technology-specific tags, declarations, and possibly scriptlets, in combination with other static HTML or XML tags. • A JSP page has the extension .jsp; this signals to the web server that the JSP engine will process elements on this page. • Pages built using JSP technology are typically implemented using a translation phase that is performed once, the first time the page is called. The page is compiled into a Java Servlet class and remains in server memory, so subsequent calls to the page have very fast response times.
  • 9. Page 8Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 8 Overview • JavaServer Pages (JSP) lets you separate the dynamic part of your pages from the static HTML. HTML tags and text <% some JSP code here %> HTML tags and text <I> <%= request.getParameter("title") %> </I> You normally give your file a .jsp extension, and typically install it in any place you could place a normal Web page
  • 10. Page 9Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 9 Client and Server with JSP
  • 11. Page 10Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 10 Translation Time • A JSP application is usually a collection of JSP files, HTML files, graphics and other resources. • A JSP page is compiled when your user loads it into a Web browser 1. When the user loads the page for the first time, the files that make up the application are all translated together, without any dynamic data, into one Java source file (a .java file) 2. The .java file is compiled to a .class file. In most implementations, the .java file is a Java servlet that complies with the Java Servlet API.
  • 12. Page 11Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 11 Simple JSP Page <%@ page info=“A Simple JSP Sample” %> <HTML> <H1> First JSP Page </H1> <BODY> <% out.println(“Welcome to JSP world”); %> </BODY> </HTML>
  • 13. Page 12Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 12 How JSP Works? User Request – JSP File Requested Server File ChangedCreate Source from JSP Compile Execute Servlet
  • 14. Page 13Classification: Restricted Review of Life Cycle of Servlet
  • 15. Page 14Classification: Restricted JSP Lifecycle 1.Translation (JSP  Servlet) 2.Compilation (Servlet compiled) 3.Loading 4.Instantiation 5.Initialization 6.Request Processing 7.Destruction
  • 16. Page 15Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 15 JSP Elements • Declarations <%! code %> • Expressions <%= expression %> • Scriptlets <% code %>
  • 17. Page 16Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 16 HTML Comment • Generates a comment that is sent to the client. • Syntax <!-- comment [ <%= expression %> ] --> • Example: <!-- This page was loaded on <%= (new java.util.Date()).toLocaleString() %> -->
  • 18. Page 17Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 17 Declaration • Declares a variable or method valid in the scripting language used in the JSP page. • Syntax <%! declaration; [ declaration; ]+ ... %> • Examples <%! String destin; %> <%! public String getDestination() {return destin;}%> <%! Circle a = new Circle(2.0); %> • You can declare any number of variables or methods within one declaration element, as long as you end each declaration with a semicolon. • The declaration must be valid in the Java programming language.
  • 19. Page 18Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 18 Declaration Example: Variables declaration <HTML> <HEAD><TITLE>JSP Declarations</TITLE></HEAD> <BODY><H1>JSP Declarations</H1> <%! private int keepCount = 0; %> <H2> Page accessed: <%= ++keepCount %> times </H2> </BODY> </HTML> Best Practice: Never use instance variables in Servlets. (Multithreading)
  • 20. Page 19Classification: Restricted Declaration example: Methods declaration <html> <head> <title>Methods Declaration</title> </head> <body> <%! int sum(int num1, int num2, int num3){ return num1+num2+num3; } %> <%= "Result is: " + sum(10,40,50) %> </body> </html>
  • 21. Page 20Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 20 Predefined Variable – Implicit Objects • request – Object of HttpServletRequest (request parameters, HTTP headers, cookies • response – Object of HttpServletResponse • out - Object of PrintWriter buffered version JspWriter • session - Object of HttpSession associated with the request • application - Object of ServletContext shared by all servlets in the engine • config - Object of ServletConfig • pageContext - Object of PageContext in JSP for a single point of access e.g. pageContext.getSession() • page – variable synonym for this object e.g. <%= ((Servlet)page).getServletInfo () %>
  • 22. Page 21Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 21 Expression • Contains an expression valid in the scripting language used in the JSP page. Syntax: <%= expression %> <%! String name = new String(“JSP World”); %> <%! public String getName() { return name; } %> <B><%= getName() %></B> • Description: An expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file. • Because the value of an expression is converted to a String, you can use an expression within a line of text, whether or not it is tagged with HTML, in a JSPfile. Expressions are evaluated from left to right.
  • 23. Page 22Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 22 Expression Example <HTML> <HEAD> <TITLE>JSP Expressions</TITLE> </HEAD> <BODY> <H2>JSP Expressions</H2> <UL> <LI>Current time: <%= new java.util.Date() %> <LI>Your hostname: <%= request.getRemoteHost()%> <LI>Your session ID: <%= session.getId() %> </UL> </BODY> </HTML>
  • 24. Page 23Classification: Restricted Expression Example 2 <html> <head> <title>JSP expression tag example1</title> </head> <body> <%= 2+4*5 %> </body> </html>
  • 25. Page 24Classification: Restricted Expression Example 3 <html> <head> <title>JSP expression tag example2</title> </head> <body> <% int a=10; int b=20; int c=30; %> <%= a+b+c %> </body> </html>
  • 26. Page 25Classification: Restricted Expression Example 4 index.jsp <html> <head> <title> JSP expression tag example3 </title> </head> <body> <% application.setAttribute("MyName", "Chaitanya"); %> <a href="display.jsp">Click here for display</a> </body> </html> display.jsp <html> <head> <title>Display Page</title> </head> <body> <%="This is a String" %><br> <%= application.getAttribute("MyName") %> </body> </html>
  • 27. Page 26Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 26 Scriptlet • Contains a code fragment valid in the page scripting language. • Syntax <% code fragment %> <% String var1 = request.getParameter("name"); out.println(var1); %> • This code will be placed in the generated servlet method: _jspService()
  • 28. Page 27Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 27 Scriplet Example <HTML> <HEAD><TITLE>Weather</TITLE></HEAD> <BODY> <H2>Today's weather</H2> <% if (Math.random() < 0.5) { %> Today will be a <B>sunny</B> day! <% } else { %> Today will be a <B>windy</B> day! <% } %> </BODY> </HTML>
  • 29. Page 28Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 28 Topics to be covered in next session • JSP vs Servlet • LifeCycle of Servlet • JSP Elements • JSP Page directive • Directives vs Action tags
  • 30. Page 29Classification: Restricted Copyright @ 2000 Jordan Anastasiade. All rights reserved. 29 Thank you!