Title: JSP Action Elements
1JSP Action Elements
2JSP Journey
- directive elements .
- scripting elements
- JSP comments.
- declarations
- expressions ....
- scriptlets..........
- action elements
- special JSP tags ..
implicit objects
3JSP Action Elements
4JSP Action Elements
- Format
- Expressed using XML syntax
- Opening tag ltjspactionElement attributevalue
gt - Body body
- Closing tag lt/jspactionElement gt
- Empty tags without body
- ltjspactionElement attributevalue /gt
5JSP Action Elements cont.
- Purpose
- To work with JavaBeans
- To include pages at request time
- To forward request to another resource etc.
6Some JSP Action Elements
- To work with JavaBeans
- ltjspuseBean /gt
- ltjspsetProperty /gt
- ltjspgetProperty /gt
- To include resources at request time
- ltjspinclude /gt
- To forward request to anther JSP or Servlet
- ltjspforward /gt
- To work with applets
- ltjspplugin /gt
- And many more.
7Working with JavaBeansusing JSP Action Elements
8Working with JavaBeans using JSP action elements
- JSP action elements also helps to work with
JavaBeans - ltjspuseBean /gt
- Makes a JavaBeans object available in a page
- ltjspsetProperty /gt
- Sets a JavaBeans property value
- ltjspgetProperty /gt
- Gets a JavaBeans property value
9JSP useBean Action Element
- jspuseBean is being equivalent to building an
object in scriptlet - lt
- MyBean m new MyBean()
- gt
- OR
- ltjspuseBean id m scope page
classvu.MyBean /gt
10JSP setProperty Action Element
- jspsetProperty is being equivalent to following
code of scriptlet - lt
- m.setName(ali)
- gt
- OR
- ltjspsetProperty id m property name
- valueali /gt
11JSP getProperty Action Element
- jspgetProperty is being equivalent to following
code of scriptlet - lt
- String name m.getName()
- out.println(name)
- gt
- OR
- ltjspgetProperty id m property name /gt
12Sharing Beans Object Scopes
13Understanding page Scope
first.jsp
second .jsp
third.jsp
request 1 or request 2
request 1
create
Values not available
MyBean m new MyBean()
MyBean m
m.setName(ali)
name ali
Page Context
14Understanding request Scope
first.jsp
second .jsp
third.jsp
fourth.jsp
request 2
request 1
request 1
create
values not available
values available
MyBean m
name ali
ServletRequest
15Understanding session Scope
first.jsp
second .jsp
third.jsp
fourth.jsp
values available
MyBean m
name ali
HttpSession
16Understanding application Scope
first.jsp
second .jsp
third.jsp
fourth.jsp
request 2
request 1
request 1
create
values available
values available
MyBean m
name ali
ServletContext
17Different Object Scopes
Most visible
Objects may be accessed only within pages where
they are created
page
Least visible
18Different Object Scopes
Most visible
Only within pages processing the request in which
they are created
request
Objects may be accessed only within pages where
they are created
page
Least visible
19Different Object Scopes
Most visible
Only from pages belonging to same session as the
one in which they were created
session
Only within pages processing the request in which
they are created
request
Objects may be accessed only within pages where
they are created
page
Least visible
20Different Object Scopes
Within all pages belonging to same application
application
Most visible
Only from pages belonging to same session as the
one in which they were created
session
Only within pages processing the request in which
they are created
request
Objects may be accessed only within pages where
they are created
page
Least visible
21Object Scopessession, request page
22Object Scopessession vs. application
23More JSP Action Elements
24JSP include Action Element cont.
- jspinclude is being equivalent to following code
of scriptlet - lt
- RequestDispatcher rd
request.getRequestDispatcher(one.jsp) - rd.include(request, response)
- gt
- OR
- ltjspinclude page one.jsp flush true /gt
25JSP forward Action Element
- To forward request to another resource
- Format
- ltjspforward pageone.jsp" /gt
- Works similar to following code of scriptlet
- lt
- RequestDispatcher rd
request.getRequestDispatcher(one.jsp) - rd.forward(request, response)
- gt