L11-EL - Session 11 EL Session 11 Expression Language(EL 1...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Session 11 – EL 10/12/2010 1 © Robert Kelly, 2001-2010 Session 11 Expression Language (EL) 1 Reading Reading Head First – pages 368-401 Sun Java EE 5 – Chapter 5 in the Tutorial java.sun.com/javaee/5/docs/tutorial/doc/JavaEETutorial.pdf Reference JSTL Reference (Chapter 3 and Appendix A) - link on CSE336 Web site (References Section) JSP 2.1 Specification – link on CSE336 Web site (References Section) – This document contains a good description of EL (Chapter 2) EL Specification – same link as the EL spec © Robert Kelly, 2001-2010 2 http://www-128.ibm.com/developerworks/java/library/j-jstl0211.html www.onjava.com/pub/a/onjava/2003/11/05/jsp.html
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Session 11 – EL 10/12/2010 2 © Robert Kelly, 2001-2010 Lecture Objectives Understand how EL can reduce the use of Java (e.g., scriptlets and JSP Expressions) in JSPs Understand how to use EL to reference object Understand how to use EL to reference object properties Understand how to combine references so that you can obtain properties of properties Know that an EL reference will look for the matching property in one of the shared objects Know the implicit objects available to you in EL © Robert Kelly, 2001-2010 3 Understand the type structure of Map objects Understand that objects containing matching get and set methods are considered to have properties How Do We Access a Bean From a JSP? Bean instantiate set values servlet JSP Page Data sources Persistence layer get values © Robert Kelly, 2001-2010 4 Before we do anything we need to get the handle to the bean
Background image of page 2
Session 11 – EL 10/12/2010 3 © Robert Kelly, 2001-2010 JSP/Bean Access You set the values of your bean in your servlet To access the bean in your JSP Use EL (language processor finds the bean) or JSP expression (you need a handle to the bean) You transfer control from your © Robert Kelly, 2001-2010 5 servlet to your JSP using either a http redirect or a forward Loading a Bean To bind an existing bean to a JSP variable (and instantiate the bean if it is not there) : <jsp:useBean id="b" class="lectures.CountBean" scope="application" /> If the bean does not already exist, this statement is equivalent (almost) to <% lectures.CountBean b = new lectures CountBean(); %> Bean class © Robert Kelly, 2001-2010 6 new lectures.CountBean(); %> JSP variable name The scope attribute specifies where a handle to the bean is stored
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Session 11 – EL 10/12/2010 4 © Robert Kelly, 2001-2010 CountBean public class CountBean implements Serializable { private int count = 0; public int getCount() { return (count); } public int fetchAndAdd() { int temp=count; count++; return (temp); } bli id tC t(i t C t) { © Robert Kelly, 2001-2010 7 public void setCount(int newCount) { this.count = count; } } Notice that fetchAndAdd returns the pre-incremented value of the counter Example-Counter <%@ page language="java" contentType="text/html" %> <html><head> <title>JSP Counter</title> <%@ page import="lecturecode.CountBean" %> </head> <body> <jsp:useBean id=“b" class="lecturecode.CountBean" scope="application" /> <h1>JSP Counter</h1>
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2011 for the course CSE 336 taught by Professor Kelly,r during the Fall '08 term at SUNY Stony Brook.

Page1 / 13

L11-EL - Session 11 EL Session 11 Expression Language(EL 1...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online