CS3220 Web and Internet Programming Expression Language (EL)

Slides:



Advertisements
Similar presentations
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Advertisements

© Yaron Kanza Advanced Java Server Pages Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.
Expression Language Lec Umair Javed©2006 Generating Dynamic Contents Technologies available  Servlets  JSP  JavaBeans  Custom Tags  Expression.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Defining classes and methods Recitation – 09/(25,26)/2008 CS 180 Department of Computer Science, Purdue University.
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
DT228/3 Web Development Java Beans. Intro A major problem with JSP is tendency to mix java code with HTML  -  web designer write the HTML and programmer.
JSP – Java Server Pages Part 2 Representation and Management of Data on the Internet.
10. JEL 과 JSTL 10-1 EL 소개 10-2 JSTL 소개 10-3 코어 라이브러리 10-4 I18N 라이브러리 10-5 SQL 라이브러리 10-6 XML 라이브러리.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
16-Oct-15 JSP Implicit Objects. 2 JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer.
EXPRESSION LANGUAGE Msc : Lê Gia Minh. EL Language : Cơ Bản  Cho phép JSP developers truy cập các đối tượng Java thông qua tag. Được dùng hiển thị nội.
JSTL: The JavaServer Pages Standard Tag Library Mark A. Kolb Security Broadband, Austin, TX
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Visibility Control.
COMP 321 Week 10. Overview Using Beans in JSP Expression Language JSTL Lab 10-1 Introduction Exam Review.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
JSP Expression Language (EL) 25-Nov-15. JSP - E XPRESSION L ANGUAGE (EL) Introduction Expression Language was first introduced in JSTL 1.0 (JSP Standard.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
EL and JSTL. JSTL Sources
Slides © Marty Hall, book © Sun Microsystems Press 1 Using JavaBeans with JSP Core Servlets & JSP book:
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Objects and Classes.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Class Fundamentals BCIS 3680 Enterprise Programming.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Java: Base Types All information has a type or class designation
JSP Elements Chapter 2.
The Expression Language Syntax
CS520 Web Programming Servlet and JSP Review
The need for Programming Languages
Working with Java.
Java: Base Types All information has a type or class designation
CS520 Web Programming Servlet and JSP Review
Creating Your OwnClasses
JavaBeans and JSP CS-422.
Chengyu Sun California State University, Los Angeles
Anatomy of a class Part I
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
Initializing Arrays char [] cArray3 = {'a', 'b', 'c'};
Control Structures: if Conditional
CS320 Web and Internet Programming Expression Language (EL)
Control Structures: for & while Loops
CS320 Web and Internet Programming Java Beans
CS320 Web and Internet Programming MVC Architecture
CS5220 Advanced Topics in Web Programming JavaScript Basics
CS2011 Introduction to Programming I Objects and Classes
CS2011 Introduction to Programming I Methods (I)
CS5220 Advanced Topics in Web Programming Node.js Basics
CS3220 Web and Internet Programming JavaScript Basics
CS3220 Web and Internet Programming Expression Language (EL)
CS2011 Introduction to Programming I Selections (I)
Java Programming Language
Rules and Tips for Good Web Programming (and Programming in General)
CS3220 Web and Internet Programming JavaScript Basics
Anatomy of a class Part I
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Presentation transcript:

CS3220 Web and Internet Programming Expression Language (EL) Chengyu Sun California State University, Los Angeles

What is EL? Expression Language (EL) Since the JSP 2.0 Specification A concise way to access data in JSP Syntax: ${ expression }

Elements of a Programming Language Comments Literals Variables and Types Operators Expressions: anything that evaluates to a single value Statements Functions Classes Packages

Comments <%-- JSP (Hidden) Comments --%> <!-- HTML Comments -->

Expression Literals Variables Operators

EL Literals true, false 23, 0x10, ... 7.5, 1.1e13, ... “double-quoted”, ‘single-quoted’ null No char type

EL Variables You cannot declare new variables using EL (after all, it’s called “expression” language). However, you can access implicit objects, scoped variables (i.e. the objects saved in application, session, and request scopes), and their properties

What Are Properties? Fields Constructor Methods Class User { private String firstName; private String lastName; public User() {} public String getFirstName() { return firstName; } public String getName() { return firstName + “ ” + lastName; } } Fields Constructor Methods

Properties Are Defined by Getters and/or Setters Class User { private String firstName; private String lastName; public User() {} public String getFirstName() { return firstName; } public String getName() { return firstName + “ ” + lastName; } } Properties firstName lastName name

About Properties Property naming conventions Property types 1st letter should be in lower case 1st letter should be capitalized in getter (accessor) and/or setter (mutator) Property types read-only property: only getter write-only property: only setter read-write property: both

Property Example What properties does Foobar have? Read-only: ?? public class Foobar { private int a, b, c, d; private boolean e; public Foobar() { a = b = c = d = 0; } public int getA() { return a; } public void setA( int a ) { this.a = a; } public int getB() { return b; } public void setC( int c ) { this.c = c; } public int getAb() { return a+b; } public boolean isE() { return e; } public void setE( boolean e ) { this.e = e; } } What properties does Foobar have? Read-only: ?? Write-only: ?? Read-write: ??

Common Problems with Property … public class Foobar { private int a, b, c, d; public Foobar() { a = b = c = d = 0; } public int getA() { return a; } public void setA( String s ) { this.a = Integer.parseInt(s); } public int getB( int x ) { return b+x; } public void setC( int c, int x ) { this.c = c+x; } public void setD( String s ) { this.d = Integer.parseInt(d); } } How many properties does Foobar have??

… Common Problems with Property A getter must have no argument A setter must have exactly one argument The type of a property must be consistent in both the getter and the setter It’s easier and safer to let Eclipse generate getters and setters instead of writing them yourself

Access Properties Using EL ${obj_name.property_name} Class A int property id String property name String[] property weekdays List<Integer> property numbers Class B A property a0 List<A> property listA

Implicit Objects in EL pageScope requestScope sessionScope pageContext servletContext session request response param, paramValues header,headerValues cookie initParam pageScope requestScope sessionScope applicationScope

Example: RequestInfo.jsp Display some information about the request Client address … Cookies and parameters Use of implicit objects Find the Java class type for the object Look for getters in the API E.g. ${pageContext.request.remoteAddr} Access elements in a collection cookie and param

EL Operators Conditional empty Other Arithmetic ? : Logical +, -, *, /, % div, mod Logical &&, ||, ! and, or, not Relational ==, !=, <, >, <=, >= eq, ne, lt, gt, le, ge Conditional ? : empty check whether a value is null or empty Other [], ., ()

EL Evaluation and Auto Type Conversion ${2+4/2} ${2+3/2} ${“2”+3/2} ${“2”+3 div 2} ${“a” + 3 div 2} ${null == ‘test’} ${null eq ‘null’} ${empty “”} ${empty null} ${empty “null”} ${“abc” lt ‘b’} ${“cs3220” > “cs2013”}

Limitation of EL Only expressions, no statements, especially no control-flow statements JSTL