Most read:
Popular archives:
JavaWorld's new look is here!
We've upgraded the site with a fresh look-and-feel, improved topical navigation, better search, new features, and expanded
community platform. Learn more about the changes to JavaWorld.
| Oracle Compatibility Developer's Guide |
| The Explosion in DBMS Choice |
Page 5 of 6
<c:url value="http://acme.com/exec/register" var="myUrl">
<c:param name="name" value="${param.name}"/>
<c:param name="country" value="${param.country}"/>
</c:url>
<a href='<c:out value="${myUrl}"/>'>Register</a>
In the code above, the param action simply defines a set of name/value pairs.
JSP allows page designers to include other pages' content with the <jsp:include> directive. JSTL extends this concept with the JSTL c:import action. c:import's big advantage is that you can specify an arbitrary URL and include page content outside of your Web application (anywhere
on the World Wide Web) or within another Web application on your server.
A set of HTTP-related tags wouldn't be complete without a way to handle HTTP redirection. JSTL supports that with the c:redirect action.
In covering JSTL support for internationalization, I assume you have a reasonable understanding of the following subjects:
Locale class
MessageFormat class
Read the internationalization-related references in the background section in Resources if you need more information on these topics.
I cover the internationalization tag library in two sections below. In the first section, I cover formatting- and parsing-related
actions (that roughly correspond to classes in the java.text package) you're likely to use even if you're not developing fully internationalized applications. In the second section,
I cover actions more specific to internationalization.
If there's a remote possibility your application will be used outside your native country, life will be easier if you build in internationalization support from the beginning. This is true even with an implementation approach as easy to use as JSTL.
If you've used the Java DateFormat and NumberFormat classes, the approach used in the tags below should look familiar, because JSTL format actions are built on top of these
classes. These Java classes generally provide a format( ) method, which converts a Java type to a formatted String and a parse( ) method, which attempts to parse a String and creates a Java object corresponding to that String.
The fmt:formatNumber action has a value attribute, which is an EL expression or literal just like the other value attributes we've seen, and a pattern attribute. This attribute mirrors patterns as defined in the NumberFormat class. The following action sends a formatted String to the JSP page's output:
<fmt:formatNumber value="1000.001" pattern="#,#00.0#"/>
In this fmt:formatNumber action, we use the type attribute to specify that we want the formatted value formatted as a currency value. We save the formatted result in a variable
name dollars. In a US locale, the following would generate the string 456.79 (note that it appropriately rounds the value for the currency used):