Sem v Unit III JSP Notes
Transcript of Sem v Unit III JSP Notes
-
8/8/2019 Sem v Unit III JSP Notes
1/135
JavaServer Pages
1
-
8/8/2019 Sem v Unit III JSP Notes
2/135
Introduction
JSP,like other JAVA APIs,is a specification provided by
sun for vendors to implement.
The JSP specification builds on the functionality providedby the servlet specification.
Then How JSP pages are different from servlets??
2
-
8/8/2019 Sem v Unit III JSP Notes
3/135
Servlets are javas answer to CGI scripts.
They are more elegant and perform better than CGI
scripts.
They execute on the server and intercept browser
requests, acting as a sort of middle layer between clients
and lower level applications.
Servlets are well suited to deciding how to handle client
requests and invoking other server side objects.
But NOT well suited for generating content.
Servlets have to be written by developers familiar with
Java3
-
8/8/2019 Sem v Unit III JSP Notes
4/135
JSP pages JSP pages,on the other hand, can be designed anddeveloped less like programs and more like web pages.
Ideal when we need to display markup with embedded
dynamic content.
But less suited to handling processing logic.
JSP pages can use JavaBeans with a specified scope or tag
extensions to achieve a clean separation of static content
and the java code that produces dynamic web applications.
This allows JSP pages to be created and maintained bydesigners with presentation skills ,they do not need to know
Java.4
-
8/8/2019 Sem v Unit III JSP Notes
5/135
Java Server PagesServlets are pure Java programs. They introduce dynamism intoweb pages by using programmatic content.
JSP technology is an extension/wrapper over the Java servlettechnology.
JSP are text based documents.
Two major components of JSP:
1. Static content: provided by HTML or XML
2. Dynamic content: generated by JSP tags and scripletswritten in Java language to encapsulate the application logic.
5
-
8/8/2019 Sem v Unit III JSP Notes
6/135
What do you mean by Static & Dynamic Contents?
6
-
8/8/2019 Sem v Unit III JSP Notes
7/135
JSP & Servlet asW
eb Components
7
-
8/8/2019 Sem v Unit III JSP Notes
8/135
What is JSP Page?
8
-
8/8/2019 Sem v Unit III JSP Notes
9/135
ASimple JSP Page
9
-
8/8/2019 Sem v Unit III JSP Notes
10/135
Output
10
-
8/8/2019 Sem v Unit III JSP Notes
11/135
ServletsServlets JSPJSP
HTML code in Java
Not easy to author
Java like code in HTML
Very easy to author
Code is compiled into
a servlet
11
-
8/8/2019 Sem v Unit III JSP Notes
12/135
JSP Benefits
12
-
8/8/2019 Sem v Unit III JSP Notes
13/135
JSP Benefits Over Competing Technologies
-Versus .NET & ASP
13
-
8/8/2019 Sem v Unit III JSP Notes
14/135
JSP BenefitsO
ver Competing Technologies
14
-
8/8/2019 Sem v Unit III JSP Notes
15/135
15
-
8/8/2019 Sem v Unit III JSP Notes
16/135
16
-
8/8/2019 Sem v Unit III JSP Notes
17/135
17
-
8/8/2019 Sem v Unit III JSP Notes
18/135
18
-
8/8/2019 Sem v Unit III JSP Notes
19/135
We have to find answers for :
19
-
8/8/2019 Sem v Unit III JSP Notes
20/135
20
-
8/8/2019 Sem v Unit III JSP Notes
21/135
21
-
8/8/2019 Sem v Unit III JSP Notes
22/135
22
-
8/8/2019 Sem v Unit III JSP Notes
23/135
23
-
8/8/2019 Sem v Unit III JSP Notes
24/135
24
-
8/8/2019 Sem v Unit III JSP Notes
25/135
25
-
8/8/2019 Sem v Unit III JSP Notes
26/135
26
-
8/8/2019 Sem v Unit III JSP Notes
27/135
27
-
8/8/2019 Sem v Unit III JSP Notes
28/135
-
8/8/2019 Sem v Unit III JSP Notes
29/135
29
-
8/8/2019 Sem v Unit III JSP Notes
30/135
30
-
8/8/2019 Sem v Unit III JSP Notes
31/135
`
31
-
8/8/2019 Sem v Unit III JSP Notes
32/135
32
-
8/8/2019 Sem v Unit III JSP Notes
33/135
33
-
8/8/2019 Sem v Unit III JSP Notes
34/135
34
-
8/8/2019 Sem v Unit III JSP Notes
35/135
35
-
8/8/2019 Sem v Unit III JSP Notes
36/135
36
-
8/8/2019 Sem v Unit III JSP Notes
37/135
37
-
8/8/2019 Sem v Unit III JSP Notes
38/135
38
-
8/8/2019 Sem v Unit III JSP Notes
39/135
39
-
8/8/2019 Sem v Unit III JSP Notes
40/135
40
-
8/8/2019 Sem v Unit III JSP Notes
41/135
41
-
8/8/2019 Sem v Unit III JSP Notes
42/135
42
-
8/8/2019 Sem v Unit III JSP Notes
43/135
43
-
8/8/2019 Sem v Unit III JSP Notes
44/135
44
-
8/8/2019 Sem v Unit III JSP Notes
45/135
45
-
8/8/2019 Sem v Unit III JSP Notes
46/135
46
-
8/8/2019 Sem v Unit III JSP Notes
47/135
-
8/8/2019 Sem v Unit III JSP Notes
48/135
48
-
8/8/2019 Sem v Unit III JSP Notes
49/135
49
-
8/8/2019 Sem v Unit III JSP Notes
50/135
50
-
8/8/2019 Sem v Unit III JSP Notes
51/135
51
-
8/8/2019 Sem v Unit III JSP Notes
52/135
52
-
8/8/2019 Sem v Unit III JSP Notes
53/135
-
8/8/2019 Sem v Unit III JSP Notes
54/135
54
-
8/8/2019 Sem v Unit III JSP Notes
55/135
55
-
8/8/2019 Sem v Unit III JSP Notes
56/135
56
-
8/8/2019 Sem v Unit III JSP Notes
57/135
57
-
8/8/2019 Sem v Unit III JSP Notes
58/135
58
-
8/8/2019 Sem v Unit III JSP Notes
59/135
59
-
8/8/2019 Sem v Unit III JSP Notes
60/135
60
-
8/8/2019 Sem v Unit III JSP Notes
61/135
61
-
8/8/2019 Sem v Unit III JSP Notes
62/135
62
-
8/8/2019 Sem v Unit III JSP Notes
63/135
63
-
8/8/2019 Sem v Unit III JSP Notes
64/135
64
-
8/8/2019 Sem v Unit III JSP Notes
65/135
65
-
8/8/2019 Sem v Unit III JSP Notes
66/135
66
-
8/8/2019 Sem v Unit III JSP Notes
67/135
67
-
8/8/2019 Sem v Unit III JSP Notes
68/135
JSP Lifecycle
68
-
8/8/2019 Sem v Unit III JSP Notes
69/135
-
8/8/2019 Sem v Unit III JSP Notes
70/135
-
8/8/2019 Sem v Unit III JSP Notes
71/135
JSP Page Lifecycle Phases -
Translation/Compilation
71
-
8/8/2019 Sem v Unit III JSP Notes
72/135
Translation/Compilation (Contd.)
72
-
8/8/2019 Sem v Unit III JSP Notes
73/135
JSP Page Lifecycle Phases -Execution
73
-
8/8/2019 Sem v Unit III JSP Notes
74/135
API for the generated Servlet
74
-
8/8/2019 Sem v Unit III JSP Notes
75/135
Initialization of a JSP Page
75
-
8/8/2019 Sem v Unit III JSP Notes
76/135
Finalization of a JSP Page
76
-
8/8/2019 Sem v Unit III JSP Notes
77/135
Examples
77
-
8/8/2019 Sem v Unit III JSP Notes
78/135
General Rules of Syntax
78
-
8/8/2019 Sem v Unit III JSP Notes
79/135
JSP Family.
79
-
8/8/2019 Sem v Unit III JSP Notes
80/135
JSP syntactic elementsType of element Element content
Template content Everything in your JSP page's source file that is not a JSPelement.Includes all static content.
Directives Instructions you place in your JSP page to tell the JSPimplementation how to go about building your page, such as to
include another file.
Scripting elements Used to embed Java code into your JSP pages.
Actions Actions provide high-level functionality, in the form of custom XML-style tags, to a JSP page without exposing the scripting language.Standard actions include those to create, modify, and otherwise
use JavaBeans within your JSP page.
80
-
8/8/2019 Sem v Unit III JSP Notes
81/135
JSP element syntaxElement
Hidden comments
Declarations
Java Languagedeclarations
Expressions
A Java expression
81
-
8/8/2019 Sem v Unit III JSP Notes
82/135
JSP element syntax (Contd.)Element
-
8/8/2019 Sem v Unit III JSP Notes
83/135
Template content
83
-
8/8/2019 Sem v Unit III JSP Notes
84/135
Template content (Contd.)
84
-
8/8/2019 Sem v Unit III JSP Notes
85/135
JSP elements - directives
Directive Purpose
page Controls properties of the JSP page.
include Includes the contents of a file into the JSP page at translationtime.
taglib Makes a custom tag library available within the including page.
85
-
8/8/2019 Sem v Unit III JSP Notes
86/135
JSP Page- directives
86
-
8/8/2019 Sem v Unit III JSP Notes
87/135
Page directive (Contd.)
87
-
8/8/2019 Sem v Unit III JSP Notes
88/135
Page directive attributesAttribute Value Default
language java java
extends superclass Implementation-dependent. This tells theJSP container to use the specified classas the superclass for the generatedservlet
import java-import-list java.lang.*, javax.servlet.http.*,
javax.servlet.*, javax.servlet.jsp.*
session true | false true
buffer Kilobytes or none 8 KB or more
autoFlush true | false true
isThreadSafe true | false true
info text NoneerrorPage URL for errorPage None
contentType MIME type;encoding text/html
88
-
8/8/2019 Sem v Unit III JSP Notes
89/135
Include directive
89
-
8/8/2019 Sem v Unit III JSP Notes
90/135
-
8/8/2019 Sem v Unit III JSP Notes
91/135
Taglib directive attributes
Attribute Description
uri Either the absolute URI specification that uniquely identifies the TLD associatedwith this prefix.
tagdir Indicates this prefix is to be used to identify tag file extensions installed in the/WEB-INF/tags directory or a subdirectory,If a TLD is present in the specified
directory, its used.O
therwise, an implicit tag library is used.O
nly one of uri ortagdir may be specified. Otherwise a translation error will occur
prefix Defines a prefix string thats used to access tags (or actions) defined in the taglibrary. Empty prefixes are illegal.The following prefixes are reserved: jsp, jspx,java, javax, servlet, sun and sunw.
91
-
8/8/2019 Sem v Unit III JSP Notes
92/135
Taglib directive - Examples
92
-
8/8/2019 Sem v Unit III JSP Notes
93/135
JSP elements - declarations
93
-
8/8/2019 Sem v Unit III JSP Notes
94/135
Declarations (Contd.)
94
-
8/8/2019 Sem v Unit III JSP Notes
95/135
Declarations - Examples
95
-
8/8/2019 Sem v Unit III JSP Notes
96/135
Implicit Objects
96
-
8/8/2019 Sem v Unit III JSP Notes
97/135
-
8/8/2019 Sem v Unit III JSP Notes
98/135
Implicit Objects (Contd.)
98
-
8/8/2019 Sem v Unit III JSP Notes
99/135
Implicit Objects (Contd.)
99
-
8/8/2019 Sem v Unit III JSP Notes
100/135
Scope Objects
100
-
8/8/2019 Sem v Unit III JSP Notes
101/135
Implicit Objects (Contd.)
101
-
8/8/2019 Sem v Unit III JSP Notes
102/135
Scope Objects (Contd.)
102
-
8/8/2019 Sem v Unit III JSP Notes
103/135
Scope Objects (Contd.)
103
-
8/8/2019 Sem v Unit III JSP Notes
104/135
JSP elements - expressions
104
-
8/8/2019 Sem v Unit III JSP Notes
105/135
Expressions - Examples
105
-
8/8/2019 Sem v Unit III JSP Notes
106/135
-
8/8/2019 Sem v Unit III JSP Notes
107/135
Scriptlets - Examples
107
-
8/8/2019 Sem v Unit III JSP Notes
108/135
Output
108
-
8/8/2019 Sem v Unit III JSP Notes
109/135
Scriptlets vs Declarations
109
-
8/8/2019 Sem v Unit III JSP Notes
110/135
JSP elements - actions
110
-
8/8/2019 Sem v Unit III JSP Notes
111/135
JSP Standard ActionsJSP Standard Actions
111
-
8/8/2019 Sem v Unit III JSP Notes
112/135
-
8/8/2019 Sem v Unit III JSP Notes
113/135
What are Java Beans ?
113
-
8/8/2019 Sem v Unit III JSP Notes
114/135
Standard actions -
114
-
8/8/2019 Sem v Unit III JSP Notes
115/135
Syntax
115
-
8/8/2019 Sem v Unit III JSP Notes
116/135
Scope
Scope Duration
page The bean will be good only within the defining JSP page and will be re-createdfor each new request.
request The bean will be good throughout that request and is available to included orforwarded pages.
session The bean will be associated with the particular session responsible for itscreation and is good for the lifetime of the session.
application The bean is common to all sessions and is good until the Web application
terminates.
116
-
8/8/2019 Sem v Unit III JSP Notes
117/135
Specification
Specification Meaning
class="className" class is the implementation class for the object.
type="typename"
class="className"
type is the type to be used for the bean within the page, andmust be compatible with the class. class is the implementationclass for the object.
type="typeName"
beanName="beanName"
type is the type to be used for the bean within the page.beanName is the name of an existing bean, and will be passedtojava.beans.Beans.instantiate(). The beanName may be a JSPexpression, whose value is computed at request time. Such anexpression must use the
-
8/8/2019 Sem v Unit III JSP Notes
118/135
Standard actions -
118
-
8/8/2019 Sem v Unit III JSP Notes
119/135
SpecificationPropertyDetails Meaning
property="*" All bean properties for which there is an HTTP requestparameter with the same name will be automatically set to thevalue of the request parameter. This is probably the single mostfrequently used form ofjsp:setProperty, typically used inconjunction with an HTTP form.
property="propertyName" Sets just that property to the corresponding request parameter.
property="propertyName"
param="parameterName"
Sets the specified property to the specified request parameter.
property="propertyName
value="propertyValue"
Sets the specified property to the specified string value, which
will be coerced to the property's type. The value may be a JSPexpression,whose value is computed at request time. Such anexpression must use the
-
8/8/2019 Sem v Unit III JSP Notes
120/135
Standard actions -
120
-
8/8/2019 Sem v Unit III JSP Notes
121/135
, and
Interaction
121
-
8/8/2019 Sem v Unit III JSP Notes
122/135
Why use JavaBeans in JSP Page ?
122
-
8/8/2019 Sem v Unit III JSP Notes
123/135
Why use JavaBeans in JSP Page ?(Contd.)
123
-
8/8/2019 Sem v Unit III JSP Notes
124/135
Why use JavaBeans in JSP Page ? (Contd.)
124
-
8/8/2019 Sem v Unit III JSP Notes
125/135
Standard actions -
125
-
8/8/2019 Sem v Unit III JSP Notes
126/135
Standard actions -
126
-
8/8/2019 Sem v Unit III JSP Notes
127/135
Include directive Vs include action
Include type Syntax Done when Includedcontent
Parsing
directive
Compilation time Static Parsed bycontainer
Action Requestprocessing time Static ordynamic Nor parsed butincluded inplace
127
-
8/8/2019 Sem v Unit III JSP Notes
128/135
Example for include action & directive
128
-
8/8/2019 Sem v Unit III JSP Notes
129/135
Output
129
-
8/8/2019 Sem v Unit III JSP Notes
130/135
Example for include action & directive
130
-
8/8/2019 Sem v Unit III JSP Notes
131/135
Output after changing the pages
131
-
8/8/2019 Sem v Unit III JSP Notes
132/135
-
8/8/2019 Sem v Unit III JSP Notes
133/135
Standard actions -
133
-
8/8/2019 Sem v Unit III JSP Notes
134/135
Standard actions -
134
-
8/8/2019 Sem v Unit III JSP Notes
135/135