How to use multiple resource bundle in same JSP?


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

Attribute

The <fmt:setBundle> tag has the following attributes −

AttributeDescriptionRequiredDefault
basenameBase name of the resource bundle family to expose as a scoped or a configuration variableYesNone
varName of the variable to store the new bundleNoReplace default
scopeScope of the variable to store the new bundleNoPage

Example

<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "fmt" %>
<html>
   <head>
      <title>JSTL fmt:setBundle Tag</title>
   </head>
   <body>
      <fmt:setLocale value = "en"/>
      <fmt:setBundle basename = "com.tutorialspoint.Example" var = "lang"/>
      <fmt:message key = "count.one" bundle = "${lang}"/><br/>
      <fmt:message key = "count.two" bundle = "${lang}"/><br/>
      <fmt:message key = "count.three" bundle = "${lang}"/><br/>
   </body>
</html>

The above code will generate the following result −

One
Two
Three

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

208 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements