MY mENU


Tuesday 10 April 2012

Expression Language - EL in JSP


Expression Language (EL) was introduced in JSP 2.0 specification. You can do almost everything like scriptlet by using EL which is simpler to understand.

Basic syntax: The syntax of expression language is very simple. No matter where it is called, it always follows the form as bellows:

${expr}
In the syntax above, expr is an expression. When the Java compiler sees the sign ${}, it evaluates the expr and injects the result in the place where ${expr} is called. Let take a look at an example:
In the above example, first we use the action useBean to instantiate a new object of the class Message and set its text property. Then we use ${msg.text} as an expression. Whencompiler sees this syntax, it evaluates the expression which is msg.text and invokes the appropriate method of the object which returns the value of text property. In this case, on the screen you will see the message "this is a message" is displayed.

Literal Values

Literal values are constants with a specific data type and they can be used in expression along with variables. There are five basic five types as follow:
  1. Boolean: true and false
  2. Integer: a combination of numbers from 0 to 9
  3. Floating Point
  4. String
  5. Null: null

No comments:

Post a Comment