[ Team LiB ] Previous Section Next Section

Recipe 24.13 Setting the Localization Context in the Deployment Descriptor


You want to configure the localization context for the JSTL tags used by a web application.


Use a context-param element in the application's 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.

Example 24-14. Setting the localization context for JSTL tags
<!-- Beginning of web.xml -->





<!-- Rest of web.xml -->

See Also

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 ] Previous Section Next Section