1 / 12

CS320 Web and Internet Programming Expression Language (EL)

Learn how to utilize Expression Language (EL) to access bean properties efficiently in JSP programming. Explore syntax, literals, operators, and variables to enhance your coding skills.

Download Presentation

CS320 Web and Internet Programming Expression Language (EL)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS320 Web and Internet ProgrammingExpression Language (EL) Chengyu Sun California State University, Los Angeles

  2. What is EL? • Expression Language (EL) • Since the JSP 2.0 Specification • A more concise way to access bean properties and write JSP expressions • vs. <jsp:getProperty> • vs. <%= expression %> • Java’s answer to scripting languages • Syntax: ${ expression }

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

  4. More Property Access Examples • Bean BeanA • int property id • String property name • String[] property weekdays • List<Integer> property numbers • Bean BeanB • BeanA property bean0 • List<BeanA> property beans

  5. Expression • Literals • Operators • Variables

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

  7. 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 Operators

  8. EL Evaluation and Auto Type Conversion

  9. 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 (i.e. the objects saved in application/session/request/page scopes by setAttribute())

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

  11. 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

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

More Related