Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Cover Story: A Practical Solution to Internationalization of a J2EE Web App

Making Web Applications Multilingual

Internationalization with JSTL
JSP standard tag libraries (JSTL) are built with inherent support for internationalization. The JSTL internationalization tags can be classified into the following two categories:

1.  Tags that support display of localized messages:

  • <fmt:setLocale>
  • <fmt:setBundle>
  • <fmt:bundle>
  • <fmt:message>
2.  Tags that support locale-specific formatting
  • <fmt:formatNumber>
  • <fmt:formatDate>
  • <fmt:parseNumber>
  • <fmt:parseDate>
These internationalization tags work directly from the locale and current resource bundle settings in the JSTL configuration. JSTL provides the "javax.servlet.jsp.jstl.core.Config" class that governs these settings. Specifically, the current user locale is stored in the configuration setting using the "Config.FMT_LOCALE" key. The resource bundle to be used for the current locale is stored in the configuration setting using an instance of helper bean "javax.servlet.jsp.jstl.fmt.LocalizationContext." This instance is configured using the "Config.FMT_LOCALIZATION_CONTEXT" key.

The <fmt:setLocale> tag enables explicit setting of the locale. It uses the "Config.FMT_LOCALE" key internally to store the locale object in the configuration so that other internationalization tags can use it. Optionally, the locale can be set in a particular scope using the "scope" attribute. The following is an example use of this tag:

<fmt:setLocale value="zh-CN" variant="discount" />

The <fmt:setBundle> tag enables explicit setting of a resource bundle for the current locale so that localized messages can be retrieved from that bundle. The mandatory "basename" attribute of this tag determines the resource bundle to load. Internally, this tag looks up the current locale using the "Config.FMT_LOCALE" key. It creates an instance of "LocalizationContext" to store the loaded bundle using the current locale, and stores that instance in the specified scope or by default in the page scope. The following is a typical use of this tag:

<fmt:setBundle basename="messages" scope="session" />

The <fmt:bundle> is a convenient tag to override the current localization context in such a way that a different resource bundle can be used within the nested scope of this tag. This tag uses the mandatory "basename" attribute to load the resource bundle using the current locale configuration setting. It then creates an instance of "LocalizationContext" to store the resource bundle and the current locale so that any other internationalization tags nested inside its body can avail themselves of that information. The following is the typical use of this tag:

<fmt:bundle basename="messages" />

The <fmt:message> tag is the major consumer of the underlying resource bundle and is the primary way of displaying localized messages in a JSP page. A stand-alone usage of this tag (shown in the following snippet) uses the underlying "LocalizationContext" instance to look up the resource bundle and retrieve messages using the value specified for the key attribute:

<fmt:message key="ui.i18n.label.shopForFlights" />

This tag has an optional "bundle" attribute that can be used to directly point to an instance of "LocalizationContext." If this attribute is specified, this tag will not look up for the "LocalizationContext" in the JSTL configuration but will instead directly access the specified instance to retrieve the resource bundle. In general, the following is the look-up order used by the <fmt:message> tag to look up the resource bundle for localized messages:

  1. The "LocalizationContext" instance specified by the "bundle" attribute
  2. The "LocalizationContext" instance specified by <fmt:bundle> tag, if nested within the <fmt:bundle> tag
  3. The "LocalizationContext" specified in the JSTL configuration either by <fmt:setBundle> or explicitly by custom Java code. The order of look up in this case is as follows:
    a. Page scope
    b. Request scope
    c. Session scope
    d. Application scope
Note that the key used to retrieve the message from the underlying resource bundle can be specified in the body of the tag. This helps in generating the key dynamically during run time, as shown in the following snippet:

<c:out value="ui.i18n.label.month.${month.month}" />

It is worth mentioning here that the default resource bundle to be used by the JSTL configuration can be specified in the "web.xml" file as follows so that there is no need to explicitly set the bundle either by using <fmt:setBundle> or by using custom Java code.


Tags that support locale-specific formatting use the current locale specified in the JSTL configuration through the "Config.FMT_LOCALE" key. The primary purpose of these tags is to format the data in a manner that is appropriate for the current locale. The <fmt:formatNumber> and <fmt:formatDate> are the most frequently used tags to display data in a locale-sensitive manner.

The <fmt:formatNumber> tag in its simplest form is used to display numbers formatted based on current locale. Optionally the "type" attribute can be specified to instruct the tag to print the numeric value as a regular number, currency, or percentage.

<fmt:formatNumber value="1000000.05"/>

Table 5 shows the formatting done by the above tag in different locales. The <fmt:formatDate> tag is used to format a date based on the current locale. The "value" attribute is used to specify the variable of java.util.Date to be formatted. The following code snippet shows an example:

<jsp:useBean id="today" class="java.util.Date"/>
<font class="generalSmallLabel" >Today: </font>
<font class="generalLabel">
<fmt:formatDate value="${today}"/></font>

Table 6 shows the date formatting for different locales.

Incorporating "DynaResourceBundle" in JSTL
It was very easy to incorporate "DynaResourceBundle" into JSTL after understanding the internals of its internationalization support. Once the custom user locale was identified by the application based on the current user request, an instance of "DynaResourceBundle" was created and set explicitly in the JSTL configuration using the "setLocale" method in the "SessionHelper" object as shown in Listing 8.

Figure 10 shows how the <fmt:message> tag interacts with "DynaResourceBundle" to retrieve the localized messages.

Setting the Page Encoding Scheme
Setting the character set encoding is a final but critical step in making sure that the content is displayed correctly. For all JSP pages, the character set encoding was set using the "pageEncoding" attribute of the "page" directive. As discussed before, "UTF-8" was set as the character encoding scheme:

<%@ page pageEncoding="UTF-8" %>

If there were many JSP pages that use a common template JSP page, it would be easy to specify the page encoding in one single location in the common template JSP.

Encoding Scheme for the Database
If the localized content is stored in a database such as Oracle, it is important to make sure that the correct character set encoding scheme is specified for the database. Oracle gives options to specify the character set encoding to be used at the time of database creation. The character set encoding used by Oracle database can be verified by executing the following SQL:


Among other things, the above SQL gives information about the character set property. The parameters "NLS_CHARACTERSET" and "NLS_NCHAR_CHARACTERSET" will indicate the character set encoding scheme used by the database. Table 7 shows an example.

The design for internationalization should be an up-front task and not an afterthought. The design and implementation of internationalization should be carried out after careful evaluation of the exact application internationalization requirements. The choice of locale plays an important role in the implementation strategy. The internationalization requirements in general will also help in determination of the implementation approach: a single set of JSPS for all locales or separate sets of JSPS per locale. Internationalization in a J2EE Web application can be accomplished by using many different methods and technologies. This article showed an example implementation using Struts framework and JSTL custom tags by extending the support provided by both in a manner suitable to the custom needs of the application. In practice, it is easy to store and manage huge amounts of localized content in a database instead of storing it in application properties files. The right choice of character set encoding is a must for internationalizing a Web application.

We would like to thank our director Virgil Bistriceanu for his continuous support and inspiration to write this article. He has monitored the design from day one and provided crucial feedback that helped us make necessary changes in the design. Because he is a hardcore technologist himself, he made sure that our design strategy aligned with the enterprise architectural direction. We also would like to thank our managers Helen Agulnik and Ken Kunz and all other team members who supported and participated in the implementation.

More Stories By Murali Kashaboina

Murali Kashaboina leads Enterprise Architecture at United Airlines, Inc. He has 15+ years of enterprise software development experience utilizing a broad range of technologies, including JEE, CORBA, Tuxedo, and Web services. Murali previously published articles in WLDJ and SilverStream Developer Center. He has master’s degree in mechanical engineering from the University of Dayton, Ohio.

More Stories By Bin Liu

Bin Liu is a lead software engineer at United Airlines. Bin has more than seven years of experience developing distributed applications using J2EE technologies, WebLogic, Tuxedo, C++, and Web services. Bin has previously published articles in WLDJ.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
Raj Kumar Kundu 06/04/08 10:52:33 PM EDT

This content is very useful for all those people who are thinking about internationalization of J2EE/ Web Based applications. It explains and points out the areas which should be rather can be considered for this activity. This can help people start thinking in right direction.
But this can be made extremely useful by providing some example files (Resource Bundle related AppResource files and the java files which are using those property files) or snaps of the java codes.

Henry 10/23/07 08:34:21 PM EDT

Is database-centric internationalization with JSF similar with this article?

@ThingsExpo Stories
DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Conference Guru has been named “Media Sponsor” of the 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organizers to pass great deals to gre...
The Internet of Things will challenge the status quo of how IT and development organizations operate. Or will it? Certainly the fog layer of IoT requires special insights about data ontology, security and transactional integrity. But the developmental challenges are the same: People, Process and Platform. In his session at @ThingsExpo, Craig Sproule, CEO of Metavine, demonstrated how to move beyond today's coding paradigm and shared the must-have mindsets for removing complexity from the develop...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.