Generating Localized Output
Now that you have an understanding of the type of internationalization support Java provides, let’s look at a concrete example. However, instead of using the internationalization classes directly in the pages, we’ll use the JSTL I18N actions based on these classes.
The example application, briefly described in the introduction to this chapter, lets visitors voice their opinion by selecting one of the answers to a question, as well as seeing how others have answered. The text, numbers, and dates are available in three different languages. Figure 13-1 shows all the pages used in this application and how they are related.
Figure 13-1. Localized poll application pages
The first page the user sees is the
poll.jsp
page, shown
in Figure 13-2. The language that displays the
contents the first time this page is requested is based on the
Accept-Language
request header value. The top part
of the page contains radio buttons for the three supported languages
and a Submit button. If the user
wants the application to be presented in another language, he selects
the corresponding radio button and clicks Submit, causing the page to be requested again, this time with a language parameter included in the request. The value of the language parameter is then used to select the corresponding locale and display the page in the selected locale’s language. Information about the ...
Get JavaServer Pages, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.