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 人气:229
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

  • Improve development efficiency restart tomcat free (free to change java code) [switch] 2011-01-01

    Make for a java developer, always a class due to the increase, or remove a method to increase, even a small change at the code and had to restart the server again. And start the server always waste of time. 10 minutes of programming for an hour or so

  • 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

  • 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 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

  • js and jsp variable in java code access solution for each variable 2010-07-29

    1. js variable for java jsp page code variable. Methods: var JS variable name = <% = JAVA variable name%> 2. java code for js variable. Description: In the JSP in; Java part is executed on the server; js part of the client's browser implementation;

  • Found during the use of it for the MyEclipse Java code for the failure of the auto-suggest, and for normal JSP was able to give prompt 2010-09-28

    Found during the use of it for the MyEclipse Java code for the failure of the auto-suggest, and for normal JSP was able to give tips. After a lot of Baidu Internet to find a solution, but because of different reasons for this phenomenon, so basically

  • MyEclipse 6.5 jsp and java code to modify the font size 2010-11-17

    1, jsp fonts English version of MyEclipse 5.5.1GA, select Preferences under the Windows menu, sub menu, open the Preferences dialog box on the left there is a General item, expand it, Below it there is a Appearence, select one of the "Colors and Font

  • 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

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



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

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.549 (s). 12 q(s)