O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

23.6. Using the Formatting JSTL Tags

Problem

You want to format a date or a number using the JSTL.

Solution

Use the fmt:formatDate and fmt:formatNumber actions.

Discussion

Internationalization or "i18n" is the process by which web developers design their web sites to accommodate visitors who use different languages.

Tip

The term "i18n" means internationalization begins with "i," is followed by 18 letters, and ends with "n." It is designed to relieve the tedium of spelling out the word several times.

Localization means adding specific resources to a web site to enable messages such as web page greetings to be translated into the visitor's language. For example, you might localize a site for Japanese visitors by adding resources that contain Japanese translations of text that appears on web pages (I cover more i18n-related Java code in Chapter 24). Example 23-6 uses the JSTL formatting tag library to display the current date and a large number in Swiss and U.S. styles.

Example 23-6. showing a date and a number for U.S. and Swiss audiences

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<%--include this taglib for i18n related actions --%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

<html>
<head><title>Formatting numbers and dates</title></head>
<body>
<h2>Dates and numbers in Swiss and US style formats</h2>

<%-- create an object representing the current date --%> <jsp:useBean id="now" class="java.util.Date"/> <%-- set the locale to German language, Swiss country ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required