|
JSTL - Localizing messages |
|
|
This tip shows how to use the JSTL internationalization actions. Our web application consists of a JSP page and required number of resource bundles (English is given in example).
Switching locales is easy for the JSP page - just change the value specified for the action. The resource bundle has a base name set to my.messages. That resource bundle base name tells the JSP container that your messages resource bundle corresponds to a properties file (or a Java class file) in the WEB-INF/classes/my/:
English properties file
page.title=Localizing Messages
company.name=My Company, Inc.
company.slogan=We Are The Best
<%@ taglib uri='http://java.sun.com/jstl/fmt' prefix='fmt'%>
<html>
<head>
////////////// specify a locale and a resource bundle base name for the
////////////// <fmt:message> actions in this page
<fmt:setLocale value='en'/>
<fmt:setBundle basename='my.messages'/>
<%-- Use <fmt:message> to display the page title --%>
<title>
<fmt:message key='page.title'/>
</title>
</head>
<body>
////////////// Use <fmt:message> to display localized messages from the
////////////// com.acme.messages resource bundle
<font size='5'>
<fmt:message key='company.name'/>
</font>
<p><fmt:message key='company.slogan'/> </p>
<hr />
</body>
</html>
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.