JSP EL expressions in

sponsored links
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

Boolean


true and false


Integer


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


String


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

Arithmetic


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


Logical


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


Relational


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


Air


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:


pageContext


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

param


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


paramValues


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


header


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


headerValues


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

pageScope


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.


requestScope


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.


sessionScope


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)


applicationScope


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
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of JSP EL expressions in

  • JavaScript inheritance

    About JavaScript inherited a small example ... <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 / / EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" conte ...

  • JavaScript String Functions Guinness

    Own JS function 1.Asc (x), Chr (x): convert characters, character code 2. Filter: Search string array of a specific string Format: v = filter (x, s [, include [, compare]]) Examples: Dim x ()={" kjwang "," wangkj "," peter ")

  • js page Jump implementation of a number of ways

    The first is: <script language="javascript" type="text/javascript"> window.location.href = "login.jsp? backurl =" + window.location.href; </ script> The second: <script language="javascript"> alert

  • EJB ant script to deploy template works

    <? xml version = "1.0" encoding = "UTF-8"?> <! - Name Project name basedir build.xml file directory -> <project name="HelloWorld" basedir="."> <! - Property variables -> <! - The sour ...

  • Hibernate Inteceptor

    The end of the project stage, the client suddenly put forward a very troublesome but normal demand, the system records all changes must be carried out. Formats such as: 2004.1.1 12:30 Ikuya wind orders Sales Order Date 2004.1.2-> 2004.1.3 The firs ...

  • RoR explained

    ROR is Ruby on Rails. Ruby is a well-known has been very good dynamic language It's dynamic language. Simple and easy. Dynamic languages are interpreted, but the performance may make a discount, but not absolute, because the application is complex, th

  • java read file

    java read documents in two ways: java.io and java.lang.ClassLoader When using the java.io, when java.lang.ClassLoader use it? (Note: If prior to read xml file java read file clearly aware of these two methods have been like! Can take much less to understa

  • FLEX: integrating Spring + Hibernate

    Before a friend also wanted to study development of FLEX. Asked me to help him to be a small sample. Spent a weekend time, to integrate a sampleproject. Client: FLEX Server: Spring2.5 + Hibernate3.2 + Hibernate-annotations3.3.1 + MySQL5 FDS: BlazeDS3 IDE:

  • Some interview questions java

    The first is the company give you a chance to meet, it is necessary to know to meet from time to equal the interview, and have a lot of companies to see you at the first time will give you a ready point of doing something trivial, these questions, althoug

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries