SlideShare a Scribd company logo
1 of 36
Copyright @ 2000 Jordan Anastasiade. All rights rese1
JavaServer Pages
In this lesson you will be learning about:
What JSP Technology is and how you can use it.
How to define and write JSP Page.
Syntax of JSP Page.
How do JSP pages work.
How is a JSP page invoked and compiled.
Use of Beans in a JSP Page.
How one could create XML pages using JSP technology.
JavaServer Pages v1.2
Copyright @ 2000 Jordan Anastasiade. All rights rese2
JavaServer Pages Technology
JavaServer Pages (JSP) technology provides a simplified,
fast way to create web pages that display dynamically-
generated content.
The JSP 1.2specification is an important part of the Java
2 Platform, Enterprise Edition. Using JSP and
Enterprise JavaBeans technologies together is a great
way to implement distributed enterprise applications
with web-based front ends.
The first place to check for information on JSP
technology is http://java.sun.com/products/jsp/
Copyright @ 2000 Jordan Anastasiade. All rights rese3
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.
Put .jsp pages into a WAR file (see Web ARchive)
Deploy (upload) the WAR file as a Web Application to your Sun
Java System Application Server Platform.
Copyright @ 2000 Jordan Anastasiade. All rights rese4
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
Copyright @ 2000 Jordan Anastasiade. All rights rese5
Client and Server with JSP
Copyright @ 2000 Jordan Anastasiade. All rights rese6
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.
Copyright @ 2000 Jordan Anastasiade. All rights rese7
Simple JSP Page
<%@ page info=“A Simple JSP Sample” %>
<HTML>
<H1> First JSP Page </H1>
<BODY>
<% out.println(“Welcome to JSP world”); %>
</BODY>
</HTML>
Copyright @ 2000 Jordan Anastasiade. All rights rese8
How JSP Works?
User Request – JSP File RequestedUser Request – JSP File Requested
ServerServer
File
Changed
File
ChangedCreate Source from JSPCreate Source from JSP
CompileCompile Execute ServletExecute Servlet
Copyright @ 2000 Jordan Anastasiade. All rights rese9
JSP Elements
Declarations <%! code %>
<jsp:declaration>
</jsp:declaration >
Expressions <%= expression %>
<jsp:expression>
</jsp:expression>
Scriplets <% code %>
<jsp:scriplet>
</jsp:scriplet >
Copyright @ 2000 Jordan Anastasiade. All rights rese10
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() %>
-->
Copyright @ 2000 Jordan Anastasiade. All rights rese11
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.
Copyright @ 2000 Jordan Anastasiade. All rights rese12
Declaration Example
<HTML>
<HEAD><TITLE>JSP Declarations</TITLE></HEAD>
<BODY><H1>JSP Declarations</H1>
<%! private int keepCount = 0; %>
<H2>
Page accessed:
<%= ++keepCount %>
times
</H2>
</BODY>
</HTML>
Copyright @ 2000 Jordan Anastasiade. All rights rese13
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
page – variable synonym for this object
Copyright @ 2000 Jordan Anastasiade. All rights rese14
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.
Copyright @ 2000 Jordan Anastasiade. All rights rese15
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>
Copyright @ 2000 Jordan Anastasiade. All rights rese16
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()
Copyright @ 2000 Jordan Anastasiade. All rights rese17
Scriplet Example
<HTML>
<HEAD><TITLE>Weather</TITLE></HEAD>
<BODY>
<H2>Today's weather</H2>
<% if (Math.random() < 0.5) { %>
Today will be a <B>suny</B> day!
<% } else { %>
Today will be a <B>windy</B> day!
<% } %>
</BODY>
</HTML>
Copyright @ 2000 Jordan Anastasiade. All rights rese18
JSP Lifecycle
jspInit()jspInit()
jspDestroy()jspDestroy()
jspService()jspService()
Servlet from JSP
Init Event
Request
Response
Destroy Event
Copyright @ 2000 Jordan Anastasiade. All rights rese19
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” />
Copyright @ 2000 Jordan Anastasiade. All rights rese20
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" ]
%>
Copyright @ 2000 Jordan Anastasiade. All rights rese21
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.
The included file can be:
1. JSP file,
2. HTML file,
3. text file.
Copyright @ 2000 Jordan Anastasiade. All rights rese22
Taglib Directive
Defines a tag library and prefix for the custom
tags used in the JSP page.
 Syntax
<%@ 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.
Copyright @ 2000 Jordan Anastasiade. All rights rese23
Server Redirection
One can forward to a text file (HTML), a CGI script, a servlet or another
JSP page.
One can only forward to a new page, provided no output of the original
page has been sent to the browser.
One may pass as many parameters as one needs with this method by
using the param tag.
The forward action ends execution of the current JSP page and removes
any existing buffered output. The new page has access to application,
request, and session objects as the starting file. A new pageContext
object is generated for the page. To the browser, it will appear you have
the originally requested page, not the page to which you are transferred.
Example:
<jsp:forward page="home/Default.jsp" >
<jsp:param name="source" value="entry"/>
</jsp:forward>
Copyright @ 2000 Jordan Anastasiade. All rights rese24
<jsp:forward>
Forwards a client request to an HTML
file, JSP file, or servlet for processing.
Syntax
<jsp:forward page="{relativeURL | <%= expression
%>}" />
<jsp:forward page="{relativeURL | <%= expression
%>}" >
<jsp:param name="parameterName"
value="{parameterValue | <%= expression
%>}" />+
</jsp:forward>
Copyright @ 2000 Jordan Anastasiade. All rights rese25
<jsp:useBean>
Locates or instantiates a bean with a specific
name and scope.
<jsp:useBean
id="beanInstanceName"
scope="page|request|session|application"
{ class="package.class" |
type="package.class" |
class="package.class" type="package.class" |
beanName="{package.class | <%= expression %>}“
}
{ /> |
> other elements
</jsp:useBean>
}
Copyright @ 2000 Jordan Anastasiade. All rights rese26
Attributes and Usage
id="beanInstanceName"
A variable that identifies the bean in the scope you specify. The name
is case sensitive and must conform to the naming conventions of the
scripting language used in the JSP page
scope="page|request|session|application“
page One can use the bean within the JSP page with the
<jsp:useBean> element or any of the page's static include files, until
the page sends a response back to the client or forwards a request to
another resource
request One can use the bean from any JSP page processing the same
request, until a JSP page sends a response to the client or forwards the
request to another resource. One can use the request object to access
the bean, for example,
request.getAttribute(beanInstanceName).
session One can use the bean from any JSP page in the same session
as the JSP page that created the bean. The bean exists across the entire
session, and any page that participates in the session can use it. The
page in which you create the bean must have a page directive with
session="true".
Copyright @ 2000 Jordan Anastasiade. All rights rese27
Different Scope
ApplicationApplication
SessionSession
RequestRequest
PagePage
Least visible
Most visible
Objects accessible only within pages
where they were created.
Objects accessible from pages
processing the request.
Objects accessible from pages
Belonging to the same session.
Objects accessible from pages
Belong to the same application.
Copyright @ 2000 Jordan Anastasiade. All rights rese28
<jsp:setProperty>
Sets a property value or values in a bean.
 Syntax
<jsp:setProperty name="beanInstanceName"
{ property="*" |
property="propertyName" [ param="parameterName" ] |
property="propertyName" value="{string | <%= expression
%>}"
}
/>
 Examples
<jsp:setProperty name="mybean" property="*" />
<jsp:setProperty name="mybean" property="username" />
<jsp:setProperty name="mybean" property="username" value="Steve" />
The <jsp:setProperty> element sets the value of one or more properties in a
bean,
using the bean's setter methods. You must declare the bean with<jsp:useBean>
before
you set a property value with <jsp:setProperty>.
Copyright @ 2000 Jordan Anastasiade. All rights rese29
<jsp:getProperty>
Gets the value of a bean property so that you
can display it in a result page.
 Syntax
<jsp:getProperty name="beanInstanceName“
property="propertyName" />
 Example:
<jsp:useBean id="calendar" scope="page" class="employee.Calendar" />
<h2>
Calendar of <jsp:getProperty name="calendar" property="username" />
</h2>
The <jsp:getProperty> element gets a bean property value using the
property's getter methods and displays the property value in a JSP
page. You must create or locate a bean with <jsp:useBean> before
you use <jsp:getProperty>.
Copyright @ 2000 Jordan Anastasiade. All rights rese30
Jsp with Beans
public class MessageBean {
private String message = "No Message";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
Copyright @ 2000 Jordan Anastasiade. All rights rese31
JavaBeans with JSP Page
<jsp:useBean id="firstBean" scope="session"
class="packBeans.MessageBean"/>
<jsp:setProperty name="firstBean"
property="message"
value="This is a message from a bean" />
<H1>Message:
<I><font color="#0000FF" size=+3>
<jsp:getProperty name="firstBean" property="message" />
</I></font>
</H1>
Copyright @ 2000 Jordan Anastasiade. All rights rese32
Handling Forms with JSP
package packBeans;
public class NameBean {
private String name;
public NameBean() {
name = null;
}
public String getName() {
return name;
}
public void setName(String aName) {
name = aName;
}
}
Copyright @ 2000 Jordan Anastasiade. All rights rese33
JSP Form
<jsp:useBean id='nb' scope='session' class=‘packBeans.NameBean'/>
<jsp:setProperty name='nb' property="*"/>
<HTML>
<BODY>
<H1>Please enter your name to be registered to JSP Course?</H1>
<FORM method="get">
<INPUT type="text" name="name" size="25">
<INPUT type="submit" value="Submit">
</FORM>
<% if ( request.getParameter("name") != null ) } %>
<%=
"Click<a href=GetName.jsp> here</a> to confirm your registration"
%>
<% } %>
</BODY>
</HTML>
Copyright @ 2000 Jordan Anastasiade. All rights rese34
JSP Results
<jsp:useBean id='nb'
scope="session“class=“packBeans.NameBean"/>
<HTML>
<HEAD>
<TITLE>Registered Name</TITLE>
</HEAD>
<BODY>
<jsp:getProperty name="nb" property="name"/>
</BODY>
</HTML>
Copyright @ 2000 Jordan Anastasiade. All rights rese35
JSP and JavaBeans
Copyright @ 2000 Jordan Anastasiade. All rights rese36
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 "%>"

More Related Content

What's hot

What's hot (19)

Jsp element
Jsp elementJsp element
Jsp element
 
Java Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom TagsJava Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom Tags
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 
Intro To Sap Netweaver Java
Intro To Sap Netweaver JavaIntro To Sap Netweaver Java
Intro To Sap Netweaver Java
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Transformation of Java Server Pages: A Modern Approach
Transformation of Java Server Pages: A Modern ApproachTransformation of Java Server Pages: A Modern Approach
Transformation of Java Server Pages: A Modern Approach
 
Jsp advance part i
Jsp advance part iJsp advance part i
Jsp advance part i
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Jsp
JspJsp
Jsp
 
jsp tutorial
jsp tutorialjsp tutorial
jsp tutorial
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Jsp
JspJsp
Jsp
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 

Viewers also liked

why development of gender education?
why development of gender education?why development of gender education?
why development of gender education?Angela Biswas
 
Leo Workshop June 2015 (1)
Leo Workshop June 2015 (1)Leo Workshop June 2015 (1)
Leo Workshop June 2015 (1)Frances Brennan
 
Group 9 _ TAXIFORSURE _ #MadnessForCricket
Group 9 _ TAXIFORSURE _ #MadnessForCricketGroup 9 _ TAXIFORSURE _ #MadnessForCricket
Group 9 _ TAXIFORSURE _ #MadnessForCricketKarthibbun Siva
 
CSP_Going_Private_F18_1010
CSP_Going_Private_F18_1010CSP_Going_Private_F18_1010
CSP_Going_Private_F18_1010Gail Fleenor
 
Assessing Students performance by Angela Uma Biswas, student of Institute of ...
Assessing Students performance by Angela Uma Biswas, student of Institute of ...Assessing Students performance by Angela Uma Biswas, student of Institute of ...
Assessing Students performance by Angela Uma Biswas, student of Institute of ...Angela Biswas
 
Cone beam computerized tomography mamita
Cone beam computerized tomography  mamitaCone beam computerized tomography  mamita
Cone beam computerized tomography mamitaMamita Sakhakarmi
 

Viewers also liked (14)

why development of gender education?
why development of gender education?why development of gender education?
why development of gender education?
 
Leo Workshop June 2015 (1)
Leo Workshop June 2015 (1)Leo Workshop June 2015 (1)
Leo Workshop June 2015 (1)
 
Group 9 _ TAXIFORSURE _ #MadnessForCricket
Group 9 _ TAXIFORSURE _ #MadnessForCricketGroup 9 _ TAXIFORSURE _ #MadnessForCricket
Group 9 _ TAXIFORSURE _ #MadnessForCricket
 
CERTIFICATE
CERTIFICATECERTIFICATE
CERTIFICATE
 
Alu Bender Photo Eng
Alu Bender Photo EngAlu Bender Photo Eng
Alu Bender Photo Eng
 
CSP_Going_Private_F18_1010
CSP_Going_Private_F18_1010CSP_Going_Private_F18_1010
CSP_Going_Private_F18_1010
 
it61
it61it61
it61
 
historia del computador
historia del computadorhistoria del computador
historia del computador
 
Assessing Students performance by Angela Uma Biswas, student of Institute of ...
Assessing Students performance by Angela Uma Biswas, student of Institute of ...Assessing Students performance by Angela Uma Biswas, student of Institute of ...
Assessing Students performance by Angela Uma Biswas, student of Institute of ...
 
Keratosis obturans
Keratosis obturansKeratosis obturans
Keratosis obturans
 
Keratosis obturans
Keratosis obturansKeratosis obturans
Keratosis obturans
 
qeeg Neuroshow
qeeg Neuroshowqeeg Neuroshow
qeeg Neuroshow
 
Cone beam computerized tomography mamita
Cone beam computerized tomography  mamitaCone beam computerized tomography  mamita
Cone beam computerized tomography mamita
 
Solid state detector mamita
Solid state detector mamitaSolid state detector mamita
Solid state detector mamita
 

Similar to Java serverpages

Similar to Java serverpages (20)

JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
 
Session 36 - JSP - Part 1
Session 36 - JSP - Part 1Session 36 - JSP - Part 1
Session 36 - JSP - Part 1
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
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 in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
Jsp
JspJsp
Jsp
 
Jsp1
Jsp1Jsp1
Jsp1
 
Jsp tutorial
Jsp tutorialJsp tutorial
Jsp tutorial
 
10 jsp-scripting-elements
10 jsp-scripting-elements10 jsp-scripting-elements
10 jsp-scripting-elements
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
 
Introduction to JSP pages
Introduction to JSP pagesIntroduction to JSP pages
Introduction to JSP pages
 
4. jsp
4. jsp4. jsp
4. jsp
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Unit 4 web technology uptu
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptu
 
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
 
PPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to serverPPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to server
 
JSP - Part 2 (Final)
JSP - Part 2 (Final) JSP - Part 2 (Final)
JSP - Part 2 (Final)
 

Recently uploaded

Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsstephieert
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 

Recently uploaded (20)

Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girls
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 

Java serverpages

  • 1. Copyright @ 2000 Jordan Anastasiade. All rights rese1 JavaServer Pages In this lesson you will be learning about: What JSP Technology is and how you can use it. How to define and write JSP Page. Syntax of JSP Page. How do JSP pages work. How is a JSP page invoked and compiled. Use of Beans in a JSP Page. How one could create XML pages using JSP technology. JavaServer Pages v1.2
  • 2. Copyright @ 2000 Jordan Anastasiade. All rights rese2 JavaServer Pages Technology JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically- generated content. The JSP 1.2specification is an important part of the Java 2 Platform, Enterprise Edition. Using JSP and Enterprise JavaBeans technologies together is a great way to implement distributed enterprise applications with web-based front ends. The first place to check for information on JSP technology is http://java.sun.com/products/jsp/
  • 3. Copyright @ 2000 Jordan Anastasiade. All rights rese3 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. Put .jsp pages into a WAR file (see Web ARchive) Deploy (upload) the WAR file as a Web Application to your Sun Java System Application Server Platform.
  • 4. Copyright @ 2000 Jordan Anastasiade. All rights rese4 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
  • 5. Copyright @ 2000 Jordan Anastasiade. All rights rese5 Client and Server with JSP
  • 6. Copyright @ 2000 Jordan Anastasiade. All rights rese6 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.
  • 7. Copyright @ 2000 Jordan Anastasiade. All rights rese7 Simple JSP Page <%@ page info=“A Simple JSP Sample” %> <HTML> <H1> First JSP Page </H1> <BODY> <% out.println(“Welcome to JSP world”); %> </BODY> </HTML>
  • 8. Copyright @ 2000 Jordan Anastasiade. All rights rese8 How JSP Works? User Request – JSP File RequestedUser Request – JSP File Requested ServerServer File Changed File ChangedCreate Source from JSPCreate Source from JSP CompileCompile Execute ServletExecute Servlet
  • 9. Copyright @ 2000 Jordan Anastasiade. All rights rese9 JSP Elements Declarations <%! code %> <jsp:declaration> </jsp:declaration > Expressions <%= expression %> <jsp:expression> </jsp:expression> Scriplets <% code %> <jsp:scriplet> </jsp:scriplet >
  • 10. Copyright @ 2000 Jordan Anastasiade. All rights rese10 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() %> -->
  • 11. Copyright @ 2000 Jordan Anastasiade. All rights rese11 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.
  • 12. Copyright @ 2000 Jordan Anastasiade. All rights rese12 Declaration Example <HTML> <HEAD><TITLE>JSP Declarations</TITLE></HEAD> <BODY><H1>JSP Declarations</H1> <%! private int keepCount = 0; %> <H2> Page accessed: <%= ++keepCount %> times </H2> </BODY> </HTML>
  • 13. Copyright @ 2000 Jordan Anastasiade. All rights rese13 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 page – variable synonym for this object
  • 14. Copyright @ 2000 Jordan Anastasiade. All rights rese14 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.
  • 15. Copyright @ 2000 Jordan Anastasiade. All rights rese15 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>
  • 16. Copyright @ 2000 Jordan Anastasiade. All rights rese16 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()
  • 17. Copyright @ 2000 Jordan Anastasiade. All rights rese17 Scriplet Example <HTML> <HEAD><TITLE>Weather</TITLE></HEAD> <BODY> <H2>Today's weather</H2> <% if (Math.random() < 0.5) { %> Today will be a <B>suny</B> day! <% } else { %> Today will be a <B>windy</B> day! <% } %> </BODY> </HTML>
  • 18. Copyright @ 2000 Jordan Anastasiade. All rights rese18 JSP Lifecycle jspInit()jspInit() jspDestroy()jspDestroy() jspService()jspService() Servlet from JSP Init Event Request Response Destroy Event
  • 19. Copyright @ 2000 Jordan Anastasiade. All rights rese19 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” />
  • 20. Copyright @ 2000 Jordan Anastasiade. All rights rese20 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" ] %>
  • 21. Copyright @ 2000 Jordan Anastasiade. All rights rese21 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. The included file can be: 1. JSP file, 2. HTML file, 3. text file.
  • 22. Copyright @ 2000 Jordan Anastasiade. All rights rese22 Taglib Directive Defines a tag library and prefix for the custom tags used in the JSP page.  Syntax <%@ 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.
  • 23. Copyright @ 2000 Jordan Anastasiade. All rights rese23 Server Redirection One can forward to a text file (HTML), a CGI script, a servlet or another JSP page. One can only forward to a new page, provided no output of the original page has been sent to the browser. One may pass as many parameters as one needs with this method by using the param tag. The forward action ends execution of the current JSP page and removes any existing buffered output. The new page has access to application, request, and session objects as the starting file. A new pageContext object is generated for the page. To the browser, it will appear you have the originally requested page, not the page to which you are transferred. Example: <jsp:forward page="home/Default.jsp" > <jsp:param name="source" value="entry"/> </jsp:forward>
  • 24. Copyright @ 2000 Jordan Anastasiade. All rights rese24 <jsp:forward> Forwards a client request to an HTML file, JSP file, or servlet for processing. Syntax <jsp:forward page="{relativeURL | <%= expression %>}" /> <jsp:forward page="{relativeURL | <%= expression %>}" > <jsp:param name="parameterName" value="{parameterValue | <%= expression %>}" />+ </jsp:forward>
  • 25. Copyright @ 2000 Jordan Anastasiade. All rights rese25 <jsp:useBean> Locates or instantiates a bean with a specific name and scope. <jsp:useBean id="beanInstanceName" scope="page|request|session|application" { class="package.class" | type="package.class" | class="package.class" type="package.class" | beanName="{package.class | <%= expression %>}“ } { /> | > other elements </jsp:useBean> }
  • 26. Copyright @ 2000 Jordan Anastasiade. All rights rese26 Attributes and Usage id="beanInstanceName" A variable that identifies the bean in the scope you specify. The name is case sensitive and must conform to the naming conventions of the scripting language used in the JSP page scope="page|request|session|application“ page One can use the bean within the JSP page with the <jsp:useBean> element or any of the page's static include files, until the page sends a response back to the client or forwards a request to another resource request One can use the bean from any JSP page processing the same request, until a JSP page sends a response to the client or forwards the request to another resource. One can use the request object to access the bean, for example, request.getAttribute(beanInstanceName). session One can use the bean from any JSP page in the same session as the JSP page that created the bean. The bean exists across the entire session, and any page that participates in the session can use it. The page in which you create the bean must have a page directive with session="true".
  • 27. Copyright @ 2000 Jordan Anastasiade. All rights rese27 Different Scope ApplicationApplication SessionSession RequestRequest PagePage Least visible Most visible Objects accessible only within pages where they were created. Objects accessible from pages processing the request. Objects accessible from pages Belonging to the same session. Objects accessible from pages Belong to the same application.
  • 28. Copyright @ 2000 Jordan Anastasiade. All rights rese28 <jsp:setProperty> Sets a property value or values in a bean.  Syntax <jsp:setProperty name="beanInstanceName" { property="*" | property="propertyName" [ param="parameterName" ] | property="propertyName" value="{string | <%= expression %>}" } />  Examples <jsp:setProperty name="mybean" property="*" /> <jsp:setProperty name="mybean" property="username" /> <jsp:setProperty name="mybean" property="username" value="Steve" /> The <jsp:setProperty> element sets the value of one or more properties in a bean, using the bean's setter methods. You must declare the bean with<jsp:useBean> before you set a property value with <jsp:setProperty>.
  • 29. Copyright @ 2000 Jordan Anastasiade. All rights rese29 <jsp:getProperty> Gets the value of a bean property so that you can display it in a result page.  Syntax <jsp:getProperty name="beanInstanceName“ property="propertyName" />  Example: <jsp:useBean id="calendar" scope="page" class="employee.Calendar" /> <h2> Calendar of <jsp:getProperty name="calendar" property="username" /> </h2> The <jsp:getProperty> element gets a bean property value using the property's getter methods and displays the property value in a JSP page. You must create or locate a bean with <jsp:useBean> before you use <jsp:getProperty>.
  • 30. Copyright @ 2000 Jordan Anastasiade. All rights rese30 Jsp with Beans public class MessageBean { private String message = "No Message"; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }
  • 31. Copyright @ 2000 Jordan Anastasiade. All rights rese31 JavaBeans with JSP Page <jsp:useBean id="firstBean" scope="session" class="packBeans.MessageBean"/> <jsp:setProperty name="firstBean" property="message" value="This is a message from a bean" /> <H1>Message: <I><font color="#0000FF" size=+3> <jsp:getProperty name="firstBean" property="message" /> </I></font> </H1>
  • 32. Copyright @ 2000 Jordan Anastasiade. All rights rese32 Handling Forms with JSP package packBeans; public class NameBean { private String name; public NameBean() { name = null; } public String getName() { return name; } public void setName(String aName) { name = aName; } }
  • 33. Copyright @ 2000 Jordan Anastasiade. All rights rese33 JSP Form <jsp:useBean id='nb' scope='session' class=‘packBeans.NameBean'/> <jsp:setProperty name='nb' property="*"/> <HTML> <BODY> <H1>Please enter your name to be registered to JSP Course?</H1> <FORM method="get"> <INPUT type="text" name="name" size="25"> <INPUT type="submit" value="Submit"> </FORM> <% if ( request.getParameter("name") != null ) } %> <%= "Click<a href=GetName.jsp> here</a> to confirm your registration" %> <% } %> </BODY> </HTML>
  • 34. Copyright @ 2000 Jordan Anastasiade. All rights rese34 JSP Results <jsp:useBean id='nb' scope="session“class=“packBeans.NameBean"/> <HTML> <HEAD> <TITLE>Registered Name</TITLE> </HEAD> <BODY> <jsp:getProperty name="nb" property="name"/> </BODY> </HTML>
  • 35. Copyright @ 2000 Jordan Anastasiade. All rights rese35 JSP and JavaBeans
  • 36. Copyright @ 2000 Jordan Anastasiade. All rights rese36 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 "%>"