Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to use resource bundle in JSP?
The
For example, the following two
Attribute
The
| Attribute | Description | Required | Default |
|---|---|---|---|
| basename | Specifies the base name of the resource bundle that is to be loaded. | Yes | None |
| Prefix | Value to prepend to each key name in |
No | None |
Example
Resource bundles contain locale-specific objects. Resource bundles contain key/value pairs. When your program needs a locale-specific resource, you keep all the keys common to all the locale but you can have translated values specific to locale. Resource bundles help in providing specific content to locale.
A Java resource bundle file contains a series of key-to-string mappings. The method that we focus on involves creating compiled Java classes that extend the java.util.ListResourceBundle class. You must compile these class files and make them available to the classpath of your Web application.
Let us define a default resource bundle as follows −
package com.tutorialspoint;
import java.util.ListResourceBundle;
public class Example_En extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{"count.one", "One"},
{"count.two", "Two"},
{"count.three", "Three"},
};
}
Let us compile the above class Example.class and make it available in the CLASSPATH of your Web application. Now you can use the following JSTL tags to display the three numbers as follows −
JSTL fmt:bundle Tag
The above code will generate the following result −
One Two Three
Try the above example without prefix as follows −
JSTL fmt:bundle Tag
The above code will generate the following result −
One Two Three
