beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
    • Learn jQuery
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

JSP Expression Tag – JSP Tutorial

By Chaitanya Singh | Filed Under: JSP tutorial

Expression tag evaluates the expression placed in it, converts the result into String and send the result back to the client through response object. Basically it writes the result to the client(browser).

Syntax of expression tag in JSP:

<%= expression %>

JSP expression tag Examples

Example 1: Expression of values

Here we are simply passing the expression of values inside expression tag.

<html>
 <head>
   <title>JSP expression tag example1</title>
 </head>
 <body>
   <%= 2+4*5 %>
 </body>
 </html>

Output:

expression-tag-example1

Example 2: Expression of variables

In this example we have initialized few variables and passed the expression of variables in the expression tag for result evaluation.

<html>
<head>
   <title>JSP expression tag example2</title>
</head>
<body>
  <%
  int a=10;
  int b=20;
  int c=30;
  %>
  <%= a+b+c %>
</body>
</html>

Output:

expression-tag-example2

Example 3: String and implicit object output

In this example we are setting up an attribute using application implicit object and then displaying that attribute and a simple string on another JSP page using expression tag.

index.jsp

<html>
<head>
<title> JSP expression tag example3 </title>
</head>
<body>
  <% application.setAttribute("MyName", "Chaitanya"); %>
  <a href="display.jsp">Click here for display</a>
</body>
</html>

display.jsp

<html>
<head>
<title>Display Page</title>
</head>
<body>
 <%="This is a String" %><br>
 <%= application.getAttribute("MyName") %>
</body>
</html>

Output:

expression-tag-output1

expression-tag-output2

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSP Tutorial

  • Basics of JSP
  • Life cycle of JSP
  • JSP in Eclipse IDE
  • Declaration tag
  • Expression tag
  • Scriptlets
  • Directives
  • Include Directive
  • Param Directive
  • Exception handling
  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty
  • Implicit Objects
  • Session implicit object
  • Validate session
  • Request implicit object
  • Response implicit object
  • Out implicit object
  • Application implicit object
  • Config implicit object
  • pageContext implicit object
  • Exception implicit object
  • Expression language
  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap