JSTL SQL Transaction<sql:transaction> Tag Example

The <sql:transaction> tag is used to group <sql:query> and <sql:update> into transactions. You can put as many <sql:query> and <sql:update> as statements inside <sql:transaction> to make them a single transaction.

It ensures that the database modifications performed by the nested actions are either committed or rolled back if an exception is thrown by any nested action.

JSTL Transaction Tag provides the capability to run SQL statement in a group. You can run multiple SQL statements at a time. It is called one single transaction. In this transaction either all statments run successfully or all fail if one statement does not run successfully.

Syntax
<sql:transaction dataSource=”<string>” isolation=”<string>”/>

JSTL Transaction Tag has following attribute.

1. dataSource Attribute: Specifies the datasource for the transaction.

2. isolation Attribute: Specifies the level of isolation for the transaction.

JSTL SQL Transaction Tag Example:-

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ page import="java.util.Date,java.text.*" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
 
<html>
<head>
<title>JSTL sql:transaction Tag</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/TEST"
     user="root"  password="cohondob"/>

<%
Date DoB = new Date("2013/10/23");
int studentId = 1111;
%>

<sql:transaction dataSource="${snapshot}">
   <sql:update var="count">
      UPDATE Students SET firstName = 'Sandhya' WHERE Id = 2222
   </sql:update>
   <sql:update var="count">
      UPDATE Students SET fistName = 'Sweetu' WHERE Id = 3333
   </sql:update>
   <sql:update var="count">
     INSERT INTO Students 
     VALUES (4444,'Neha', 'Verma', '2013/10/23');
   </sql:update>
</sql:transaction>

<sql:query dataSource="${snapshot}" var="result">
   SELECT * from Students;
</sql:query>
 
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>DoB</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
<td><c:out value="${row.dob}"/></td>
</tr>
</c:forEach>
</table>
 
</body>
</html>

Now try to access above JSP, which should display the following result:

Emp ID First Name Last Name DOB
1111 Dinesh Rajput 2013/10/23
2222 Anu Rajput 2013/10/23
2222 Sweetu Rajput 2013/10/23
2222 Sandhya Bansal 2013/10/23
<<Previous <<   || Index ||   >>Next >>

JSTL SQL dateParam<sql:dateParam> Tag Example

The <sql:dateParam> tag is used as a nested action for <sql:query> and <sql:update> supply a date and time value for a value placeholder. If a null value is provided, the value is set to SQL NULL for the placeholder.

JSTL dateParam Tag provides the value of the date parameter. In SQL update statement, date paramter is sent using JSTL dateParam tag.

Syntax
<sql:dateParam value=”<string>” type=”<string>”/>

JSTL Param Tag has following attribute.

1. value Attribute: Specifies the value of the date parameter.
2. type Attribute: Specifies the type of the parameter. It can be DATE , TIME or TIMESTAMP. TIMESTAMP is the default value.

JSTL SQL date param Tag Example:
To start with basic concept, let us create a simple table Students table in TEST database and create few records in that table as follows:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ page import="java.util.Date,java.text.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
 
<html>
<head>
<title>JSTL sql:dataParam Tag</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/TEST"
     user="root"  password="pass123"/>

<%
Date DoB = new Date("12-08-1987");
int empId = 1111;
%>
 
<sql:update dataSource="${snapshot}" var="count">
   UPDATE Students SET dob = ? WHERE Id = ?
   <sql:dateParam value="<%=DoB%>" type="DATE" />
   <sql:param value="<%=studentId%>" />
</sql:update>
 
<sql:query dataSource="${snapshot}" var="result">
   SELECT * from Students;
</sql:query>
 
<table border="1" width="100%">
<tr>
   <th>Emp ID</th>
   <th>First Name</th>
   <th>Last Name</th>
   <th>DoB</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
   <td><c:out value="${row.id}"/></td>
   <td><c:out value="${row.first}"/></td>
   <td><c:out value="${row.last}"/></td>
   <td><c:out value="${row.dob}"/></td>
</tr>
</c:forEach>
</table>
 
</body>
</html>

Now try to access above JSP, which should display the following result:

Emp ID First Name Last Name DOB
1111 Dinesh Rajput 12-08-1987
2222 Sweety Rajput 20-11-1989
<<Previous <<   || Index ||   >>Next >>

JSTL SQL Param<sql:param> Tag Example

JSTL Param Tag provides the value of the parameter. In SQL update statement, paramters are sent using JSTL Param tag. The <sql:param> tag is used to set the parameters to the SQL query. We use this tag to set the placeholders and data to match the placeholder position to insert the data into the database or to update the database records. This tag is used as a nested tag inside the <sql:query> to provide the parameters to the query.

Syntax
<sql:param value=”<string>”/>

JSTL Param Tag has following attribute.

1. value Attribute: Specifies the value of the parameter.

JSTL <sql:param> Tag Example:-
The following example takes input from the employee and inserts the entered citizen information into the database using the combination of <sql:query> and <sql:param> tags. The list of records are displayed in tabular manner once the new record has been inserted.

Now let us write a JSP which will make use of <sql:update> to execute a SQL DELETE statement to delete one record with id = 103 from the table as follows:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<html>
<head>
<title>JSTL sql:param Tag</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost:3306/DAVDB"
     user="root"  password="root"/>

<c:set var="empId" value="3333"/>

<sql:update dataSource="${snapshot}" var="count">
  DELETE FROM Employees WHERE Id = ?
  <sql:param value="${empId}" />
</sql:update>

<sql:query dataSource="${snapshot}" var="result">
   SELECT * from Employees;
</sql:query>
 
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
<td><c:out value="${row.age}"/></td>
</tr>
</c:forEach>
</table>

</body>
</html>

Now try to access above JSP, which should display the following result:

Emp ID First Name Last Name Age
1111 Dinesh Rajput 27
2222 Sweety Rajput 23
<<Previous <<   || Index ||   >>Next >>

JSTL <sql:update>SQL UPDATE Tag Example

JSTL Update Tag provides capability to write insert, update or delete statements directly from JSP.

The <sql:update> tag executes the provided SQL query through its body or through its sql attribute. Execution SQL queries using <sql:update> tag does not return any data. This tag can execute INSERT, UPDATE and DELETE statements.

Syntax-
<sql:update var=”<string>” scope=”<string>” sql=”<string>” dataSource=”<string>”/>

JSTL <sql:Update> Tag has following attributes.

1. datasource Attribute: Specifies the datasource. Make sure that you already created datasource using serDataSource tag before writing query.

2. sql Attribute: Specifies the SQL statement to run on database.

3. var Attribute: Store the result of SQL statement.

JSTL SQL UPDATE Tag Example:
Now let us write a JSP which will make use of <sql:update> to execute a SQL INSERT statement to create one record in the table as follows:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL SQL Tags - setDataSource Example</title>
</head>
<body>

 <sql:setDataSource driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/database_name"
            var="localSource" 
            user="database_user"  
            password="database_password"/>
<sql:update dataSource="${snapshot}" var="count">
   INSERT INTO Employees VALUES (333, 27, 'Anamika', 'Rajput');
</sql:update>
 <sql:query dataSource="${localSource}" var="result">
SELECT * from Employees;
</sql:query>
 
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
<td><c:out value="${row.age}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>

Now try to access above JSP, which should display the following result:

Emp ID First Name Last Name Age
1111 Dinesh Rajput 27
2222 Sweety Rajput 23
3333 Anamika Rajput 23
<<Previous <<   || Index ||   >>Next >>

JSTL SQL Query Tag <sql:query> Example

JSTL Query Tag provides capability to fetch the data from databased by executing query directly from JSP and it can be stored in a variable to use later with the help of scope attribute.

JSTL SQL Query Tag has following attributes.

1. datasource Attribute: Specifies the datasource. Make sure that you already created datasource using serDataSource tag before writing query.

2. sql Attribute: Specifies the SQL statement to run on database.

3. var Attribute: Store the result of SQL statement.

Syntax-
<sql:query

  var=”<string>”

  scope=”<string>”

  sql=”<string>”

  dataSource=”<string>”

  startRow=”<string>”

  maxRows=”<string>”/>

JSP SQL <sql:query> tag Example:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL SQL Tags - setDataSource Example</title>
</head>
<body>

 <sql:setDataSource driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/database_name"
            var="localSource" 
            user="database_user"  
            password="database_password"/>

 <sql:query dataSource="${localSource}" var="result">
SELECT * from Employees;
</sql:query>
 
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
<td><c:out value="${row.age}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>


Now try to access above JSP, which should display the following result:

Emp ID First Name Last Name Age
1111 Dinesh Rajput 27
2222 Sweety Rajput 24
<<Previous <<   || Index ||   >>Next >>

JSTL SQL SetDataSource<sql:setDataSource> Example

JSTL setDataSource Tag provides capability to create a datasource directly from JSP and it can be stored in a variable to use later with the help of scope attribute.

Syntax-
<sql:setDataSource

  var=”<string>”

  scope=”<string>”

  dataSource=”<string>”

  driver=”<string>”

  url=”<string>”

  user=”<string>”

  password=”<string>”/>

JSP <sql:setDataSource> Tag has following attributes.

1. driver Attribute: Specifies the driver to connect database. For each database there is a separate driver. In this example, we are connecting to MySQL database and hence driver is com.mysql.jdbc.Driver

2. url Attribute: Specifies the location of the database.

3. var Attribute: Specifies the variable which holds the dataSource once it is created.

4. user Attribute: Specifies the user you already created to access database.

5. password Attribute: Specifies the password for the user you already assigned to access database.

JSP setDataSource Example:

Consider the following information about your MySQL database setup:

  • We are using JDBC MySQL driver.
  • We are going to connect to TEST database on local machine.
  • We would use user_id and mypassword to access TEST database.

All the above parameters would vary based on your MySQL or any other database setup. Keeping above parameters in mind, following is a simple example to use setDataSource tag:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL SQL Tags - setDataSource Example</title>
</head>
<body>

 <sql:setDataSource driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/database_name"
            var="localSource" 
            user="database_user"  
            password="database_password"/>

 <sql:query dataSource="${localSource}" 
            sql="SELECT * FROM employee WHERE salary > 10000" 
            var="result" />
 
</body>
</html>

As shown above setDataSource Tag set data source in a variable localSource. Using this data source, you can do SQL operations directly from JSP.

<<Previous <<   || Index ||   >>Next >>

JSTL Format Tag <fmt:requestEncoding> Example

The <fmt:requestEncoding> tag is used to specify the character encoding of the request. The character encoding specified using this tag is used to decode the incoming forms data entered by the user. We must use this tag to set the character encoding if the encoding used is different from the ISO-8859-1.

Even if the contentType is defined in the JSP page directive by the programmer, the character encoding must be specified because the actual user’s locale may be different from the defined value in the page directive.

Syntax
<fmt:requestEncoding value=”<string>”/>

Attribute:
The tag has following attributes:

key: Name of character encoding you want to apply when decoding request parameters.

You use the tag when you want to specify character encoding for decoding data posted from forms. This tag must be used with character encodings that are different from ISO-8859-1. The tag is required since most browsers do not include a Content-Type header in their requests.

The purpose of the tag is to specify the content type of the request. You must specify the content type, even if the encoding of the page generating the response is specified via the contentType attribute of a page directive. This is because the response’s actual locale (and thus character encoding) may differ from the value specified in the page directive.

If the page contains an I18N-capable formatting action that sets the response’s locale (and thus character encoding) by calling ServletResponse.setLocale(), any encoding specified in the page directive will be overridden.

Example-
The following JSP code sets the character encoding to UTF-8 and displayed localized messages.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL fmt:requestEncoding Tag</title>
</head>
<body>
<fmt:requestEncoding value="UTF-8" />
<fmt:setBundle basename="myapp" var="lang"/>
<fmt:setLocale value="en"/>
<fmt:message key="Name" bundle="${lang}"/><br/>
<fmt:message key="Address" bundle="${lang}"/><br/>
<fmt:message key="Number" bundle="${lang}"/><br/>
</body>
</html>

myapp.properties

Name=Dinesh
Address=Noida
Number=9988998899

This would produce following result:

<<Previous <<   || Index ||   >>Next >>

JSTL fmt Tag message <fmt:message> Example

<fmt:message> tag is used to map the key from the key-value paired mapped localized message and returns the value by replacing the key to the respective value.

Syntax
<fmt:message

   key=”<string>”

   bundle=”<string>”

   var=”<string>”

   scope=”<string>”/>


Attributes of <fmt:message>:

key : This attribute is an optional attribute that is used for specifying the key (key from the key-value paired localized message) of which value you want to show.
bundle : This attribute is an optional attribute that is used for specifying the Localization context in whose resource bundle message key’s value you want to show.
var : This attribute is an optional attribute that is used for specifying the name of the scoped variable that have stored the localized message.
scope : This attribute is an optional attribute and is used for specifying the scope of var.

Example :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL fmt:message Tag</title>
</head>
<body>
<fmt:setBundle basename="myapp" var="lang"/>
<fmt:setLocale value="hi_IN"/>
<fmt:message key="Name" bundle="${lang}"/><br/>
<fmt:message key="Address" bundle="${lang}"/><br/>
<fmt:message key="Number" bundle="${lang}"/><br/>
</body>
</html>

myapp.properties

Name=u0926u093Fu0928u0947u0936
Address=u0928u094Bu090Fu0921u093E
Number=9988998899

Output :

When the execution process will be completed successfully an output will be displayed on your browser as :

<<Previous <<   || Index ||   >>Next >>

JSTL timeZone & setTimeZone fmt Tag Example <fmt:timeZone> <fmt:setTimeZone>

<fmt:timeZone> tag is used to specify the time zone. It’s scope is limited to its body, it parses the actions that are nested into its body.

The <fmt:timeZone> tag is used to specify the time zone information for any date formatting in its body. This tag is different from <fmt:setTimeZone> in that, <fmt:setTimeZone> is used to set the default time zone. However, the <fmt:timeZone> tag sets the time zone for the tags within its body. Rest of the JSP page uses the time zone set by the <fmt:setTimeZone> or the default time zone.

Syntax-
<fmt:timeZone value=”<string>”/>

Attributes of <fmt:timeZone> tag:

value : This is a required attribute that specifies the name of a time zone/time zone IDs supported by java or an instance of the java.util.TimeZone.

The following JSP code displays the current date using the default time zone and displays current date using the GMT-8 time zone. The GMT-8 time zone is set using the <fmt:timeZone> tag. Notice that we are displaying the date within the body of the <fmt:timeZone> tag.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>&lt;fmt:timeZone&gt; Demo</title>
  </head>
  <body>
    <h1>&lt;fmt:timeZone&gt; Demo</h1>
    <c:set var="today" value="<%=new java.util.Date()%>" />
    <c:set var="timeZone" value="GMT-8"/>
    Date in the current time zone:
    <strong><fmt:formatDate value="${today}" type="both" /></strong>
    <br/>
    Date in the GMT-8 time zone (nested in &lt;fmt:timeZone&gt; tag):
    <fmt:timeZone value="${timeZone}">
    <strong>
          <fmt:formatDate value="${today}" timeZone="${timeZone}" type="both" />
        </strong>
    </fmt:timeZone>
  </body>
</html>

Output–

JSTL fmt Tag <fmt:setTimeZone> Example-

The <fmt:setTimeZone> is used to set the required time zone value. We can also copy the time zone object into the scoped variable for later use.

In JSP <fmt:setTimeZone> tag of JSTL fmt tag library is used to set a specified time zone or default time zone. The specified time zone may be either a specific name of time zone, supported by java or an instance of the TimeZone class of Java’s utility package and the name or an instance can be passed into the required attribute named “value” of this tag.

Attributes of <fmt:setTimeZone> tag
value : This is a required attribute that specifies the name of a time zone/time zone IDs supported by java or an instance of the java.util.TimeZone.
var : This is an optional attribute that defines the name of the scoped variable kept the time zone of java.util.TimeZone type.
scope : This is an optional attribute that may be used for specifying the scope of the attribute ‘var’.

Syntax-
<fmt:setTimeZone value=”<string>” var=”<string>” scope=”<string>”/>
 
The following JSP code displays the current date using the default time zone and assigns the time zone to the GMT-8 using the <fmt:setTimeZone> tag. Also displays the date using the newly set time zone.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>&lt;fmt:setTimeZone&gt; Demo</title>
  </head>
  <body>
    <h1>&lt;fmt:setTimeZone&gt; Demo</h1>
    <c:set var="today" value="<%=new java.util.Date()%>" />
    <p>Date in the current time zone: 
    <strong>
      <fmt:formatDate value="${today}" type="both" timeStyle="long" dateStyle="long" />
    </strong></p>
    <fmt:setTimeZone value="GMT-8" />
    <p>Date in the GMT-8 time zone: 
    <strong>
      <fmt:formatDate value="${today}" type="both" timeStyle="long" dateStyle="long" />
    </strong></p>
  </body>
</html>


Output-

<<Previous <<   || Index ||   >>Next >>

JSTL fmt Tag setBundle Example <fmt:setBundle>

The <fmt:setBundle> tag is used to load a resource bundle and stores it in the named scoped variable or the bundle configuration variable.

<fmt:setBundle> tag in JSTL is used in a JSP page to set the resource bundle. A resource bundle is loaded by this tag and is stored into the named scoped variable or the bundle configuration variable.

Attributes of <fmt:setBundle>

  • basename : This is a required attribute used for specifying the base name of resource bundle . Basename is a resource name, follows the same component separator dot (.) as the package uses for specifying the fully qualified class name. It does not uses the any type of suffixes such as .properties, .class etc.
  • var : This is an optional attribute used for specifying the name of the exported base name to a variable.
  • scope : This is an optional attribute is used for specifying the scope of the variable.

Example-
An example is being given here will demonstrate you how to use the <fmt:setBundle> tag. In this example I have created a Properties file named myapp.properties that contains the key-value pair. Value of key are the English characters. Then created a JSP page named index.jsp into which I have set the locale using the <fmt:setLocale> tag. And then uses the <fmt:setBundle> tag to load the bundle resource from the resource variable. So as an output you will see the values written in English language.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL fmt:setBundle Tag</title>
</head>
<body>
<fmt:setBundle basename="myapp" var="lang"/>
<fmt:setLocale value="en"/>
<fmt:message key="Name" bundle="${lang}"/><br/>
<fmt:message key="Address" bundle="${lang}"/><br/>
<fmt:message key="Number" bundle="${lang}"/><br/>
</body>
</html>

myapp.properties

Name=Dinesh
Address=Noida
Number=9988998899

Output :

When the execution process will be completed successfully an output will be displayed on your eclipse browser as :

<<Previous <<   || Index ||   >>Next >>