100% found this document useful (3 votes)
6K views1 page

I18n With JSTL

To internationalize a web application using JSTL: 1. Add the JSTL jar and tag library descriptor files to the web application. 2. Configure context parameters and taglib definitions in web.xml. 3. Create resource bundle properties files for localized messages. 4. Access localized messages in JSPs using JSTL fmt:message tags.

Uploaded by

thiamteck
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
6K views1 page

I18n With JSTL

To internationalize a web application using JSTL: 1. Add the JSTL jar and tag library descriptor files to the web application. 2. Configure context parameters and taglib definitions in web.xml. 3. Create resource bundle properties files for localized messages. 4. Access localized messages in JSPs using JSTL fmt:message tags.

Uploaded by

thiamteck
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

i18n with JSTL

1. Download JSTL from Jakarta Taglibs Project


2. From the JSTL taglibs binary, extract the jstl.jar and standard.jap and place into the WEB-INF/lib/ of
your web app.
3. From the JSTL taglib binary, extract the tld files into WEB-INF/tld/ of your web app
4. Add 3 context param and 2 taglib definition into web.xml as below:
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>ApplicationResources</param-value>
</context-param>

<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
<param-value>en_US</param-value>
</context-param>

<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.locale</param-name>
<param-value>en_US</param-value>
</context-param>

<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
</taglib>

5. Create your resource bundle (i.e. ApplicationResources_en_US.properties) and place it into WEB-
INF/classes/
msg.1=this is msg 1
msg.2=msg 2

6. Basically your webapps is now ready for i18n. below is an example of the JSP (i18n.jsp):
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<c:if test="${param['lang'] != null}">


<fmt:setLocale value="${param['lang']}" scope="session"/>
</c:if>

<html>
<head><title>Test i18n capable tag of JSTL</title></head>
<body>
<p>msg.1 = <fmt:message key="msg.1"/></p>
<p>msg.2 = <fmt:message key="msg.2"/></p>

<p><a href="?lang=en_US">English</a></p>
<p><a href="?lang=fr">French</a></p>
</body>
</html>

Thiam Teck @ 24 Sept 2007


http://thiamteck.blogspot.com/

You might also like