Download presentation
Presentation is loading. Please wait.
1
JSP Action Elements Lec - 37
2
JSP Journey directive elements ………………………. scripting elements
JSP comments………………………………. declarations ………………………………… expressions …………………………..…….. scriptlets……………………………… action elements special JSP tags ………………………….…. implicit objects
3
JSP Action Elements
4
JSP Action Elements Format Expressed using XML syntax
Opening tag <jsp:actionElement attribute=“value” … > Body body Closing tag </jsp:actionElement > Empty tags without body <jsp:actionElement attribute=“value” … />
5
JSP Action Elements cont.
Purpose To work with JavaBeans To include pages at request time To forward request to another resource etc.
6
Some JSP Action Elements
To work with JavaBeans <jsp:useBean /> <jsp:setProperty /> <jsp:getProperty /> To include resources at request time <jsp:include /> To forward request to anther JSP or Servlet <jsp:forward /> To work with applets <jsp:plugin /> And many more….
7
Working with JavaBeans using JSP Action Elements
8
Working with JavaBeans using JSP action elements
JSP action elements also helps to work with JavaBeans <jsp:useBean /> Makes a JavaBeans object available in a page <jsp:setProperty /> Sets a JavaBeans property value <jsp:getProperty /> Gets a JavaBeans property value
9
JSP useBean Action Element
jsp:useBean is being equivalent to building an object in scriptlet <% MyBean m = new MyBean(); %> OR <jsp:useBean id = “m” scope = “page” class=“vu.MyBean ”/>
10
JSP setProperty Action Element
jsp:setProperty is being equivalent to following code of scriptlet <% m.setName(“ali”); %> OR <jsp:setProperty id = “m” property = “name” value=“ali” />
11
JSP getProperty Action Element
jsp:getProperty is being equivalent to following code of scriptlet <% String name = m.getName(); out.println(name); %> OR <jsp:getProperty id = “m” property= “name” />
12
Sharing Beans & Object Scopes
13
Understanding page Scope
first.jsp second .jsp third.jsp request 1 request 1 or request 2 create Values not available MyBean m = new MyBean(); MyBean m m.setName(“ali”); [name = ali] Page Context
14
Understanding request Scope
first.jsp second .jsp third.jsp fourth.jsp request 1 request 1 request 2 create values not available values available MyBean m [name = ali] ServletRequest
15
Understanding session Scope
first.jsp second .jsp third.jsp fourth.jsp request 1 request 1 request 2 create values available values available MyBean m [name = ali] HttpSession
16
Understanding application Scope
first.jsp second .jsp third.jsp fourth.jsp request 1 request 1 request 2 create values available values available MyBean m [name = ali] ServletContext
17
Different Object Scopes
Most visible page Objects may be accessed only within pages where they are created Least visible
18
Different Object Scopes
Most visible Only within pages processing the request in which they are created request page Objects may be accessed only within pages where they are created Least visible
19
Different 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 page Objects may be accessed only within pages where they are created Least visible
20
Different Object Scopes
Within all pages belonging to same application Most visible application 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 page Objects may be accessed only within pages where they are created Least visible
21
Object Scopes session, request & page
22
Object Scopes session vs. application
23
More JSP Action Elements
24
JSP include Action Element cont.
jsp:include is being equivalent to following code of scriptlet <% RequestDispatcher rd = request.getRequestDispatcher(“one.jsp”); rd.include(request, response); %> OR <jsp:include page = “one.jsp” flush= “true” />
25
JSP forward Action Element
To forward request to another resource Format <jsp:forward page=“one.jsp" /> Works similar to following code of scriptlet <% RequestDispatcher rd = request.getRequestDispatcher(“one.jsp”); rd.forward(request, response); %> Notes -You are not permitted to specify false for the flush attribute (until JSP 1.2) -Don’t forget that trailing slash - XML syntax!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.