Home Jsp Simple-jsp-example Expression Language Basic Arithmetic



Expression Language Basic Arithmetic
Posted on: February 9, 2008 at 12:00 AM
EL means the expression language , it makes it possible to easily access application data stored in JavaBeans components.

Expression Language Basic Arithmetic

        

EL means the expression language , it makes it possible to easily access application data stored in JavaBeans components. The jsp expression language allows a page author to access a bean using simple syntax such as $(name).  Before JSP 2.0, we could  use only  a scriptlet, JSP expression, or a custom tag to include server state in the jsp page output. Expression Language (EL) was first introduced in JSTL 1.0. EL makes it easier to integrate server side state with the presentation output. 

EL expression is always written between the delimiters ${ and }. In the JSP page response, the result of expression evaluation replaces the expression and its delimiters in the template text. Within tags, expression can be used only in attribute values.

The basic Expression Language arithmetic are: Addition (+), subtraction (-), multiplication (*), division (/ or div), and modulus (% or mod) are all supported in Expression Language. Error conditions, like division by zero are handled easily by the expression language.

In this example we are just using the arithmetic expression for EL.

The code of the program is given below:

<html>
  <head>
    <title>Basic Arithmetic</title>
  </head>
  <body>
    <h1>Basic Arithmetic</h1>
    <hr>
    In this example we are doing basic arthmetic.
 Error conditions, like
    division by zero, are handled gracefully.
    <br>
    <blockquote>
      <code>
        <table border="1">
          <thead>
	    <td><b>EL Expression</b></td>
	    <td><b>Result</b></td>
	  </thead>
	  <tr>
	    <td>\${2}</td>
	    <td>${2}</td>
	  </tr>
	  <tr>
	    <td>\${2 + 2}</td>
	    <td>${2 + 2}</td>
	  </tr>
	  <tr>
	    <td>\${2.2 + 2.3}</td>
	    <td>${2.2 + 2.3}</td>
	  </tr>
	  <tr>
	    <td>\${2.2E4 + 2.4}</td>
	    <td>${2.2E4 + 2.4}</td>
	  </tr>
	  <tr>
	    <td>\${-2 - 2}</td>
	    <td>${-2 - 2}</td>
	  </tr>
	  <tr>
	    <td>\${2 * 2}</td>
	    <td>${2 * 2}</td>
	  </tr>
	  <tr>
	    <td>\${2/4}</td>
	    <td>${2/4}</td>
	  </tr>
	  <tr>
	    <td>\${2 div 4}</td>
	    <td>${2 div 4}</td>
	  </tr>
	  <tr>
	    <td>\${2/0}</td>
	    <td>${2/0}</td>
	  </tr>
	  <tr>
	    <td>\${12%4}</td>
	    <td>${12%4}</td>
	  </tr>
	  <tr>
	    <td>\${12 mod 4}</td>
	    <td>${12 mod 4}</td>
	  </tr>
    <tr>
      <td>\${(1==2) ? 3 : 4}</td>
      <td>${(1==2) ? 3 : 4}</td>
    </tr>
	</table>
      </code>
    </blockquote>
  </body>
</html>

The output of the program is given below:

Download this example.

Related Tags for Expression Language Basic Arithmetic:
cjspidestlsyntaxserverscriptlanguageioincludecustommakeoutputjstlippageexpressiontagstatenameusingintidsimplejsforiewithwastoexpress2.0presentationldlanssiwsbeaneitaxauthputuseulimfirstceinintegrateasstamntouttrsidsidebealetjclestaxscriptletallagemeintroratessuspessbeforeatauthorkincirllmplpresspreeadustatccrvsimxpscrssriripthstaccessatipleplpronlyonomonl


More Tutorials from this section

Ask Questions?    Discuss: Expression Language Basic Arithmetic  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.