|[ Team LiB ]|
Recipe 24.13 Setting the Localization Context in the Deployment Descriptor
A localization context is a set of resources such as ResourceBundles that your web application's use to provide locale information for a JSP. If the JSP is displaying translated text, it can use JSTL tags (such as fmt:fmtMessage) that detect the user's locale, and then searches within the localization context for the proper text to display.
Set the localization context with a context-param element in web.xml. The parameter name must be javax.servlet.jsp.jstl.fmt.localizationContext. Its value is the fully qualified basename of the ResourceBundle that you have installed in the web application. Example 24-14 shows a context-param element that points to the ResourceBundle we have used throughout this chapter.
Add this type of element to your deployment descriptor as an alternative to using the JSTL tag fmt:setBundle inside JSPs to specify a ResourceBundle.
<!-- Beginning of web.xml --> <context-param> <param-name> javax.servlet.jsp.jstl.fmt.localizationContext </param-name> <param-value>i18n.WelcomeBundle</param-value> </context-param> <!-- Rest of web.xml -->
Chapter 23 on the JSTL; Recipe 24.2 on detecting the client locale in a JSP; Recipe 24.6 on using a ResourceBundle in a JSP; Recipe 24.8 on formatting dates; Recipe 24.10 on formatting currencies; Recipe 24.12 on formatting percentages.
|[ Team LiB ]|