Generating Localized Output

Now that you have an understanding of the type of internationalization support Java provides, let’s look at a concrete example. But instead of using the internationalization classes directly in the pages, let’s use a set of custom actions based on these classes. Using custom actions minimizes the need for Java code in the JSP pages, making it easier for page authors to develop an internationalized site.

The example application, briefly described in the introduction to this chapter, lets visitors voice their opinions 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 11.1 shows all pages used in this application and how they are related.

Localized poll application pages

Figure 11-1. Localized poll application pages

The first page the user sees is the poll.jsp page, shown in Figure 11.2. The language used to display the contents the first time this page is displayed is based on the Accept-Language header value in the request. 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 or she 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 ...

Get Java Server Pages 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.