JSP EL expressions in

1, JSP EL language definition

EL (Expression Language) Objective: To make JSP easier to write.
Expression language inspired by ECMAScript and the XPath expression language, which provides simplified expressions in the JSP in the method. It is a simple language, based on the available namespace (PageContext attributes), nested properties and on the set of operators (arithmetic type, relational and logic-based) access to operator, mapping to the Java class static methods can be spread function and a set of implicit objects.

EL provides a JSP scripting elements to use run-time expressions outside the function. Scripting element refers to the page file can be used to embed Java code in JSP elements. They are often used for objects that affect the operation and implementation of the content generated by the calculation. JSP 2.0 EL expression will be added as a scripting element.

Second, JSP EL Introduction

1 grammar
$ (Expression)
2, [] and. Operator
EL provide "." And "[]" two operators to access the data.
When you want to access the property name contains special characters, such as. Or? Such as letters or numbers are not symbols, they have to use "[]." For example:
$ (User.My-Name) should be replaced by $ (user ["My-Name"])
If you want to when the dynamic value, you can use "[]" to do, and "." Values can not be dynamic. For example:
$ (SessionScope.user [data]) is a variable in the data
3, the variable
EL access the variable data is simple, for example: $ (username). It means that out of a range variable named username.
Because we did not specify which of a range of username, so it will sequence from the Page, Request, Session, Application range search.
If the way to find the username, the direct return, not to look down, but if all of the range are found, would return null.
Properties range in the name of the EL
Page PageScope
Request RequestScope
Session SessionScope
Application ApplicationScope

Second, JSP EL expression in the effective

Effective expression can contain text, operator, variable (object reference) and the function call. We will learn these effective expressions of each:

1, text

JSP expression language defines expressions used in the following text:

Writing Text value

true and false


And Java like. Can contain any positive or negative, such as 24, -45,567

Floating Point

And Java like. Can contain any positive or negative floating point numbers, for example-1.8E-45, 4.567


Any single or double quotes the string limit. For the single quotes, double quotes and backslashes, use the backslash character as escape sequence. Must be noted that if both ends of the string to use double quotes, you do not need to escape single quotation marks.

Null null

2 operators

JSP expression language provides the following operators, most of which are commonly used in Java operators:

Term Definition

+, - (Binary ),*,/, div,%, mod, - (one dollar)


and, & &, or ,||,!, not


==, Eq,! =, Ne,, gt, <=, le,> =, ge. Compared with other values, or Boolean, string, integer or floating-point type the text for comparison.


Empty operator is a prefix operation that can be used to determine the value is empty.

Conditional A? B: C. According to the results of the assignment to assignment A B or C.

3, implicit object

JSP expression language defines a set of implicit objects, many objects and expressions in the JSP scriplet available:


JSP page context. It can be used to access the JSP implicit objects, such as request, response, session, out, servletContext so. For example, $ (pageContext.response) response object for the page assignment.

In addition, several implicit objects available, allowing easy access to the following objects:

Term Definition

The request parameter name is mapped to a single string parameter values (by calling ServletRequest.getParameter (String name) get). getParameter (String) method returns the parameters with a specific name. Expression $ (param.name) is equivalent to request.getParameter (name).


The request parameter name is mapped to a numeric array (by calling ServletRequest.getParameter (String name) get). It is very similar to the param implicit object, but it is to retrieve a string array rather than a single value. Expression $ (paramvalues.name) is equivalent to request.getParamterValues (name).


Will request the first name of the map to a single String header value (by calling ServletRequest.getHeader (String name) get). Expression $ (header.name) is equivalent to request.getHeader (name).


Will request the first name of the map to a numeric array (by calling ServletRequest.getHeaders (String) get). It is very similar to the first implicit object. Expression $ (headerValues.name) is equivalent to request.getHeaderValues (name).

cookie Cookie name will be mapped to a single cookie object. Sent to the server, client requests access to one or more cookie. Expression $ (cookie.name.value) return with a specific name of the first cookie value. If the request contains a number of the same name cookie, you should use $ (headerValues.name) expression.
initParam Context initialization parameter name will be mapped to a single value (by calling ServletContext.getInitparameter (String name) get).

In addition to these two types of implicit objects in addition to the scope of some object allows access to a variety of variables, such as the Web context, session, request, page:

Term Definition

The name of the page scope variable is mapped to its value. For example, EL expression $ (pageScope.objectName) can be used to access a JSP page in the range of objects, you can also use $ (pageScope.objectName.attributeName) to access object properties.


The scope of the request variable name is mapped to its value. The object allows access to request object. For example, EL expression $ (requestScope.objectName) can be used to access a range of JSP request object, you can also use $ (requestScope.objectName.attributeName) to access object properties.


If the scope of the variable name will be mapped to its value. The object allows access to the session object. For example:

$ SessionScope.name)


The application range of the variable name is mapped to its value. Cain-type objects allow access to the application range of the object.

Third, with particular emphasis on:

1, note that when the expression is referenced by name one of these objects, return the corresponding object rather than the corresponding property. For example: if an existing pageContext attribute containing some other value, $ (pageContext) also return PageContext object.

2, note that <% @ page isELIgnored = "true"%> that are disabled for EL language, TRUE is prohibited. FALSE said they were not prohibited. JSP2.0 EL is enabled in the default language.

4, an example

1, for example,

<% = Request.getParameter ("username")%> is equivalent to $ (param.username)

2, for example, but the following sentence to be completed EL language is empty, if a username is not displayed null, but does not display the value.

JSP EL expressions in

<% = User.getAddr ()%> equivalent to $ (user.addr).

3, for example:

<% = Request.getAttribute ("userlist")%> is equivalent to $ (requestScope.userlist)

4, for example, Principle 3 above cases.

$ (SessionScope.userlist) 1

$ (SessionScope.userlist) 2

$ (ApplicationScope.userlist) 3

$ (PageScope.userlist) 4

$ (Uselist) meaning: the implementation of the order of 4123.

"." Back to just a string, no real built-in objects, can not call the object.

4, for example,

<% = User.getAddr ()%> is equivalent to $ (user.addr)

The first sentence of the previous user, as a variable.

The second sentence, user, must be in a certain range of properties.

JSP EL expressions in

分类:Java 时间:2010-07-11 人气:264
blog comments powered by Disqus


  • How to use the js code or Java code jsp tag 2011-05-05

    JSP tag is still very convenient, such as Struts, Spring and other JSP tags provided to us, you can use them to get some variable or calculation. For example struts2 of <s:url value="/admin/unmi.action"/> automatically for us in front of t

  • Java language coding standards (Java Code Conventions 2009-01-05

    At the beginning of Notes ") http://www.huihoo.org/code/java_code_conventions.html - Package and the introduction of statements (see "package and the introduction of statements") - Class and interface declarations (see "classes and int

  • How access to the database, java or jsp binary image 2010-08-23

    How to access java or jsp binary images to the database a few days before school music station suddenly see the picture on the original is stored in the database, is binary instead of using the path stored in the Internet to find that most of the str

  • java code programming optimization 2010-03-26

    Procedures for the use of available resources (memory, CPU time, network bandwidth, etc.) is limited, the purpose of optimization is to allow programs to use the least resources to complete the scheduled tasks. Optimization usually contains two aspec

  • jsp page using java code 2010-05-28

    Previously, I do not like jsp pages directly to use java code block, mosaic java code, but after work, use this situation, I changed the mind, in fact, it has the convenience of his office ah! <%@ page language="java" import="java.util.*

  • Java or jsp how to access the binary image to the database 2010-08-23

    Java or jsp how to access the binary image to the database a few days before the music stops suddenly see the school's image was originally stored in the database is binary instead of using the path stored in the Internet search found that most recru

  • Java using the summary keyword keyword final.static 2010-03-29

    1, final According to the procedure context, Java keyword final there, "This can not be changed" or "end state" meaning, it can be modified non-abstract class, non-abstract class member methods and variables. You may need to stop for t

  • Java dependency injection standard (JSR-330) Introduction 2010-03-30

    Java dependency injection standard (JSR-330, Dependency Injection for Java) 1.0 specification was released in October this year. The specification is mainly for users of dependency injection, while the injector to achieve, the configuration is not fo

  • Java code to build a pool of threads 2010-04-25

    In modern operating systems, there is a very important concept - the thread, almost all currently popular operating systems support threads, thread the concept of the process from the operating system, the process has its own virtual address space an

  • Java language coding standard (Java Code Conventions) 2010-05-13

    http://www.huihoo.org/code/java_code_conventions.html Java language coding standard (Java Code Conventions) http://www.360doc.com/content/07/0807/09/17598_658049.shtml Java naming http://book.51cto.com/art/200903/112298.htm master the Java naming con

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.040 (s). 11 q(s)