CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.

Slides:



Advertisements
Similar presentations
More on Processing User Input BCIS 3680 Enterprise Programming.
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.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
DT211/3 Internet Application Development
CS320 Web and Internet Programming JSP Scripting Elements and Page Directives 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.
DT228/3 Web Development JSP: Directives and Scripting elements.
Faculty of Information Technology © Copyright UTS Faculty of Information Technology 2008 – JSPJSP /32549 Advanced Internet Programming Java Server.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
Using JavaBeans Components in JSP Documents. Contents 1. Why using beans? 2. What are beans? 3. Using Beans: Basic Tasks 4. Sharing Beans 5. Practice.
What Are Beans? beans are simply Java classes that are written in a standard format. A bean class must have a zero-argument (default) constructor. A bean.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Jordan Anastasiade. All rights reserved.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Organization of the platform Your application Java language Java Servlet API JavaServer Pages (JSP) JSTL Your web pages.
Mark Dixon 1 12 – Java Beans. Mark Dixon 2 Session Aims & Objectives Aims –To cover the use of Java Beans Objectives, by end of this week’s sessions,
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Slides © Marty Hall, book © Sun Microsystems Press 1 JSP Scripting Elements Core Servlets & JSP book:
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
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
COMP 321 Week 10. Overview Using Beans in JSP Expression Language JSTL Lab 10-1 Introduction Exam Review.
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.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
EL and JSTL. JSTL Sources
Web Technologies Java Beans & JSP By Praveen Kumar G.
Slides © Marty Hall, book © Sun Microsystems Press 1 Using JavaBeans with JSP Core Servlets & JSP book:
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Intermediate JSP Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic Java.
JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
Chapter 14 Using JavaBeans Components in JSP Documents.
CS320 Web and Internet Programming Web Application and MVC Chengyu Sun California State University, Los Angeles.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Introduction to Server-Side Web JavaBeans; basic concepts and syntax.
JSP Action Elements Lec - 37.
JSP Elements Chapter 2.
The Expression Language Syntax
CS520 Web Programming Servlet and JSP Review
JSP: Actions elements and JSTL
Java Server Pages By: Tejashri Udavant..
CS520 Web Programming Servlet and JSP Review
COMP9321 Web Application Engineering Semester 2, 2017
Scripted Page Web App Development (Java Server Pages)
Scope and State Handling in JSPs
JavaBeans and JSP CS-422.
Chengyu Sun California State University, Los Angeles
Introduction to Java Bean
Introduction to Java Bean
JSP Standard Tag Library
CS320 Web and Internet Programming Expression Language (EL)
CS320 Web and Internet Programming Java Beans
CS320 Web and Internet Programming MVC Architecture
CS3220 Web and Internet Programming Expression Language (EL)
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming Expression Language (EL)
Chengyu Sun California State University, Los Angeles
Scripted Page Web Application Development (Java Server Pages)
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Presentation transcript:

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

Problems with Scripting Elements Mixing presentation and processing hard to debug hard to maintain No clean and easy way to reuse code Solution – separate out Java code Java Beans Custom taglib

Java Beans for Dummies A zero-argument constructor No public class variables Properties Properties are defined by getter and/or setters, e.g. getFoo() and setFoo() Properties != Class variables

About Bean Properties Property naming conventions 1 st letter is always in lower case 1 st letter must 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

Bean Property Example What properties does Foobar have? Read-only: ?? Write-only: ?? Read/write: ?? public class Foobar { private int a, b, c, d; 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; } }

Common Problems with Bean 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); } } Get and set A do not have the same types

… Common Problems with Bean 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

Bean and JSP JSP Bean EL

Bean Tags and Attributes jsp:useBean class id scope  page (default)  request  session  application jsp:getProperty name property jsp:setProperty name property value param

Example: BGColor.jsp Use a bean BGBean to control the background color of a JSP page

Example: RequestCounter2.jsp Use Counter bean How do we increment the counter?? Understand scopes Application Session Request Page

Need for EL Using to access bean properties is tedious EL

What is EL? Expression Language (EL) Part of the JSP 2.0 Specification A more concise way to access bean properties and write JSP expressions  vs. Java’s answer to scripting languages Syntax: ${ expression }

Example: BGColor.jsp Revisited Use EL to access the bean properties ${ bean_name.property_name }

Example: ShowCookie.jsp Display the value of the cookie JSESSIONID PHP: echo $HTTP_COOKIE_VARS[JSESSIONID] JSP Scriptlet?? EL

Expression Literals Operators Variables

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

EL Operators Arithmetic +, -, *, /, % 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 param.a} ${empty null} ${empty “null”} ${“abc” lt ‘b’} ${“cs320” > “cs203”}

EL Variables You cannot declare new variables using EL (after all, it’s called “expression” language). However, you can access beans, implicit objects, and previously defined scoped variables.

Implicit Objects in EL 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. ${request.remoteAddr} Access elements in a collection  cookie and param

Example: ShoppingCart.jsp Store bean and Cart bean Simple properties  E.g. number of products in the cart Collection properties  E.g. list of products Display, add to, and remove from cart

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